Answer to Question #217936 in C++ for Rosie

Question #217936
Question 6: write a program uses for loop that print the square of each odd number, that is, 1 9 25 49 81 121 169 225 289 361



Question 7: write a program uses for loop that print those numbers divisible by 3, that is, 3 6 9 12 15 18
1
Expert's answer
2021-07-17T10:42:03-0400
#include <iostream>

using namespace std;

int main() {
    int n = 20;
    // Question 6
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) cout << i * i << ' ';
    }
    cout << '\n';
    // Question 7
    for (int i = 1; i <= 20; i++) {
        if (i % 3 == 0) cout << i << ' ';
    }

    return 0;
}

Output:
1 9 25 49 81 121 169 225 289 361 
3 6 9 12 15 18 

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
APPROVED BY CLIENTS