Question

#include <iostream> using namespace std; int main() { } Write a program that solicits a user-specified...

#include <iostream>

using namespace std;

int main()

{

}

Write a program that solicits a user-specified amount of numbers and their values, and then computes the average value, as well as their parity (how many even versus odd).

Below is the console content of an example run of the completed program.

 
 
 

How many numbers would you like to store? 8

 

Enter the 8 numbers: 0 7 3 1 5 6 2 3

 
 

Average value: 3.125

 

Parities: 3 even, 5 odd

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main()
{
// Ask user to enter number to score
int num;
cout<<"How many numbers would you like to store? ";
cin>>num;

// Declare array of num size
int arr[num];

// Take input
cout<<"Enter the "<<num<<" numbers: ";
for(int i =0 ;i<num;i++){
cin>>arr[i];
}

double avg = 0;
int even = 0;
int odd = 0;

// Iterate loop over array
// Calculate average, odd and even
// If number is divisible by 2, its even else odd
for(int i = 0;i<num;i++){
avg+=arr[i];

if(arr[i]%2==0){
even+=1;
}else{
odd+=1;
}
}

avg/=num;

// Print result
cout<<"Average value: "<<avg<<endl;
cout<<"Parities: "<<even<<" even, "<<odd<<" odd"<<endl;
return 0;
}

OUTPUT-

Add a comment
Know the answer?
Add Answer to:
#include <iostream> using namespace std; int main() { } Write a program that solicits a user-specified...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT