Answer to Question #172127 in C++ for sara

Question #172127

Write a program that uses for loops to perform the following steps:

 Output all odd numbers between firstNum and secondNum. Hint: the difference between two consecutive is 2. 


1
Expert's answer
2021-03-19T03:22:42-0400
#include <iostream>
using namespace std;
int main() {
    const int firstNum = 3, secondNum = 26;
    for(int i = firstNum; i <= secondNum; i++) {
        if(i % 2) {
            cout << i << " ";
        }
    }
    cout << "\n";
    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
APPROVED BY CLIENTS