Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program named Exam2Programl that prompts the user to say how many intege

ID: 3682585 • Letter: W

Question

Write a program named Exam2Programl that prompts the user to say how many integer, he wishes to enter, then asks him to enter that many integers The program then displays the squareroot of the sum of the user's even integers and the square root of the sum of the user's odd integers, with higher one displayed first (If they are equal, you can display either one first) the program must contain an is Even function that takes an integer parameter and returns a Boolean value, and a main function that gets the user's input, computes the sums by using is Even. and displays the result' Two sample shown below. Your prompts and outputs should look exactly like this (spelling, punctuation, and so on). How many integers would you like to enter 6 Please enter your 6 integers: 3 12 10 29 8 4 The square root of the sum of your even integers is 5.83. The square root of the sum of your odd integers. is 5.66 How many integers would you like to enter? 6 Please enter your 6 integers: 3 12 5 29 8 4 The square root of the sum of your odd integers is 6.08 The square root of the sum of your even integers is 4.90.

Explanation / Answer

#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;
//function to check given n is even or odd
bool isEven(int n)
{
if(n%2==0)
return true;
else
return false;
}

int main()
{
int n,evenSum=0,oddSum=0;
double evenSumSQRT,oddSumSQRT;
cout<<"How many integers would you like to enter?";
cin>>n;
int array[n];
cout<<"Please enter your "<<n<<" integers :";
for(int i=0; i<n; i++)
cin>>array[i];
//calculating sum of even and odd numbers
for(int i=0; i<n; i++)
{
if(isEven(array[i]))
evenSum+=array[i];
else
oddSum+=array[i];


}
//calculating sqrt of sum of even and odd sums
evenSumSQRT=sqrt(evenSum);
oddSumSQRT=sqrt(oddSum);
//print largest first
if(evenSumSQRT>oddSumSQRT)
{
cout << "The square of the sum of your even integers is " <<std::fixed<<setprecision(2)<<evenSumSQRT<< endl;
cout << "The square of the sum of your odd integers is " <<std::fixed<<setprecision(2) <<oddSumSQRT<< endl;
}
else
{
cout << "The square of the sum of your odd integers is " <<std::fixed<<setprecision(2) <<oddSumSQRT<< endl;
cout << "The square of the sum of your even integers is " <<std::fixed<<setprecision(2)<<evenSumSQRT<< endl;

}
return 0;
}

OUTPUT:

Sample Run1:
How many integers would you like to enter?6
Please enter your 6 integers :3 12 10 29 8 4
The square of the sum of your even integers is 5.83
The square of the sum of your odd integers is 5.66


Sample Run2:
How many integers would you like to enter?6
Please enter your 6 integers :3 12 5 29 8 4
The square of the sum of your odd integers is 6.08
The square of the sum of your even integers is 4.90

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote