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>
using namespace std;
int main()
{
for (int i = 1; i <= 20; i++) {
if (i % 3 == 0 || i % 5 == 0) {
continue;
}
else
{
cout << " Cube value of " << i << " = " << i * i * i << endl;
}
}
return 0;
}
Comments
Leave a comment