No Sevens


Collapse 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

  • I 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.

  • I do not see a reason to check if number divides by 7.

    I 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!

  • This is weird for me, it works until the number 14. How can it be the case?

  • @Davin, for specific feedback from admins on your code, consider signing up for membership or the bootcamp.

  • For finding out if the number ends with 7 you should check (number % 10) != 7

  • What is the correct phrasing for the print function. I keep getting an error when trying to test my code? Thanks

  • I keep getting errors in part of the code that I'm not altering. Can I please get some help on this? Thanks

  • This usually means you've changed the boilerplate code. In such a case, carefully copy your actual code, click "reset" and try again.

  • I 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

  • I think I would like to get recognition for possibly having devised the longest, clunkiest and ugliest answer so far:

    my code

  • Ha, now I see the pitiful 3 lines of code given as the official answer...That won't cut it.
    [insert smiley emoticon here.]

  • in R

    for (i in 1:50) {

    if (i == 7) {
    next
    }
    else if (i %% 10 == 7) {
    next
    }
    else print(i)

    }

  • #include

    using namespace std;

    int main()
    {

    for(int i=0;i<=50;i++)
    {
        if( (i==7) || (i%7==0) || (i%10==7) )
        {
            continue;
    
        }
        else{
            cout<<i<<endl;
        }
    }
    

    }

All Node Comments
Contact Us
Sign in or email us at [email protected]