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.
#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;
}
Comments
Leave a comment