Answer to Question #142542 in C++ for mosab sawafta

Question #142542
Write a C++ program that uses for loops to perform the following steps:

1. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum).

2. Output all the odd numbers between firstNum and secondNum.

3. Output the sum of all the even numbers between firstNum and secondNum.

4. Output the numbers between 1 and 10 and and their squares. (This has nothing to do with the user input.)

5. Output the sum of the square of the odd numbers between firstNum and secondNum.

6. Output all uppercase letters. (This also has nothing to do with the user input.)
1
Expert's answer
2020-11-05T12:13:41-0500
#include <iostream>

using namespace std;

int main()
{
    int firstNum, secondNum;
    cout << "1. Input firstNum and secondNum:\n";
    cin >> firstNum >> secondNum;
    
    int sumOfEven=0, sumOfSqOdd=0;
    
    cout << "2. All odd numbers between " << firstNum << " and " << secondNum << ":\n";
    for (int i=firstNum; i<=secondNum; i++)
    {
        if (i%2==1)
        {
            cout << i << " ";
            sumOfSqOdd += i*i;
        }
        else
        {
            sumOfEven += i;
        }
    }
    cout << "\n3. Sum of evens:\n" << sumOfEven <<endl;
    cout << "4. Numbers between 1 and 10 and and their squares:\n";
    for (int i=1; i<=10; i++)
    {
        cout << i << " " << i*i << endl;
    }
    cout << "5. Sum of the square of the odd numbers:\n";
    cout << sumOfSqOdd << endl;
    cout << "6. All uppercase letters:\n";
    for (char i='A'; i<='Z'; i++)
    {
        cout << i << " ";
    }
}

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

Assignment Expert
06.11.20, 00:26

Dear visitor, please use panel for submitting new questions

mosab saleh sawafta
05.11.20, 22:53

Write a program that uses do while loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Output all odd numbers between firstNum and secondNum. Output the sum of all even numbers between firstNum and secondNum. Output the numbers and their squares between 1 and 10 . Output the sum of the square of the odd numbers between firstNum and secondNum. Output all uppercase letters

Leave a comment

LATEST TUTORIALS
New on Blog