Answer to Question #176544 in C++ for puja

Question #176544

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

a.   Prompt the user to input two integers: firstNum and secondNum

(firstNum must be less than secondNum).

b.   Output all odd numbers between firstNum and secondNum.

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

d.   Output the numbers and their squares between 1 and 10.

e.   Output the sum of the square of the odd numbers between firstNum

and secondNum.

f.   Output all uppercase letters.


1
Expert's answer
2021-03-29T03:53:51-0400
#include <iostream>
using namespace std;
int main(){
    int firstNum = 0, secondNum = 0, sum = 0, oddsum = 0;
    for(int i = firstNum; i <= secondNum; i++, i--){
        cout<<"First number must be less than second number.\n";
        cout<<"Input first number: ";
        cin>>firstNum;
        cout<<"Input second number: ";
        cin>>secondNum;
        if(firstNum < secondNum)
            break;
        }
    cout<<"\nAll odd numbers between "<<firstNum<<" and "<<secondNum<<"\n";
    for(int i = firstNum; i <= secondNum; i++){
        if(i % 2 != 0){
            cout<<i<<" ";
            oddsum += i * i;
        }
    }
    cout<<"\nSum of all even numbers between "<<firstNum<<" and "<<secondNum<<"\n";
    for(int i = firstNum; i <= secondNum; i++){
        if(i % 2 == 0){
            sum += i;
        }
        if(i == secondNum)
            cout<<sum;
    }
    cout<<"\nNumbers and their squares between 1 and 10. \n";
    for(int i = 1; i <= 10; i++){
        cout<<i<<" "<<i * i<<endl;
    }
    cout<<"Sum of squares of odd numbers between "<<firstNum<<" and "<<secondNum<<"\n";
    cout<<oddsum<<endl;
    for(int i = 'A'; i <= 'Z'; i++){
        char c = i;
        cout<<c<<" ";
    }
    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