Answer to Question #320147 in C++ for Last two.2

Question #320147

Print out the cube values of the numbers ranging from 1 to 20 (inclusive). However, if the number is divisible by either 3 or 5, do not include them in printing and proceed with the next numbers. Tip: When skipping through special values, make use of the keyword continue and put them inside a conditional statement.

1
Expert's answer
2022-03-29T05:19:18-0400
#include <iostream>

int main() {
    for (int i=1; i<=20; i++) {
        if (i%3 == 0)
            continue;
        if (i%5 == 0)
            continue;
        std::cout << i*i*i << std::endl;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog