Answer to Question #179693 in C++ for ngcf

Question #179693

Write a c++ program that use a whole loop to perform the following tasks?

 ‐Prompt to accept two number 

display all odd numbers between the numbers

- display the sun of all even number between the number

-output the number and its square for all number between the give number

  • - out put the sum of the square if the odd number b/n the number
1
Expert's answer
2021-04-08T18:40:24-0400
#include <iostream>
using namespace std;


int main() {
    int n1, n2, i;    
    int sum_even = 0;
    int sum_of_sq = 0;
    int count = 0;


    cout << "Enter two numbers: ";
    cin >> n1 >> n2;


    i = n1;
    while (i <= n2) {
        if (i % 2 == 1)
            cout << i << " ";
        else
            sum_even += i;
        i++;
    }
    cout << endl;
    cout << "the sum of even number is " << sum_even << endl;


    i = n1;
    cout << "number \t its square" << endl;
    while (i<=n2) {
        cout << "  " << i << "\t " << i*i << endl;
        sum_of_sq += i*i;
        count++;
        i++;
    }
    if (count % 2 == 1)
        cout << "The sum of squares is " << sum_of_sq << endl;

}

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