No Sevens
Collapse Content
Show Content
The next few challenges will involve loops, and this challenge can get you started.
The Kingdom of Zumbania recently banned the number 7. Please print all the numbers from 1 to 50 but skip all multiples of 7. Also, skip any number that has a 7 in it, such as 27
.
Challenge
Print all the numbers as above, with each number on its own line.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Кирилл Варивода
Jan 13, 5:50 AMI can't even imagine using mod operator "to see if a number ends in 7". Web search didn't helped too.
Also, I do not see a reason to check if number divides by 7.
Кирилл Варивода
Jan 13, 10:49 AMI got it.Then I put my code and it all works. It's just a mess of statements.
Now I see Explanation below, it's so easy now using only one if statement!
Davin
Jun 13, 7:39 AMThis is weird for me, it works until the number 14. How can it be the case?
Learneroo
Jun 13, 9:28 AM@Davin, for specific feedback from admins on your code, consider signing up for membership or the bootcamp.
Viktor Ayadi
Jul 27, 9:20 AMFor finding out if the number ends with 7 you should check (number % 10) != 7
Bernard Mitchell
May 19, 11:04 AMWhat is the correct phrasing for the print function. I keep getting an error when trying to test my code? Thanks
Bernard Mitchell
May 19, 10:16 PMI keep getting errors in part of the code that I'm not altering. Can I please get some help on this? Thanks
Learneroo
May 19, 10:36 PMThis usually means you've changed the boilerplate code. In such a case, carefully copy your actual code, click "reset" and try again.
Bernard Mitchell
May 20, 11:16 AMI keep getting an "cant find symbol error" when I try to print my int.. I'm going to have to cheat on this one. sigh
Bolke
Sep 24, 3:42 PMI think I would like to get recognition for possibly having devised the longest, clunkiest and ugliest answer so far:
my code
Bolke
Sep 24, 3:45 PMHa, now I see the pitiful 3 lines of code given as the official answer...That won't cut it.
[insert smiley emoticon here.]
avisuisse
Oct 6, 8:45 PMin R
for (i in 1:50) {
if (i == 7) {
next
}
else if (i %% 10 == 7) {
next
}
else print(i)
}
Dheeraj Parmar
Aug 4, 12:46 PM#include
using namespace std;
int main()
{
}