C Plus Plus program, and i use cin and cout In this problem you will write a sma
ID: 3530070 • Letter: C
Question
C Plus Plus program, and i use cin and cout In this problem you will write a small program which reads five positive real numbers from the user and outputs their maximum, minimum, arithmetic mean, geometric mean, and harmonic mean. You will need to use a small amount of programming logic (e.g, the if-else statement and Boolean comparison operators Ask the user to input five positive numbers using the following text: Enter 5 Positive Numbers: Identify the largest of the five values and output it on its own line using the following text: Biggest: Identify the smallest of the five values and output it on its own line using the following text: Smallest: Calculate the arithmetic mean of the five numbers and output it on its own line using the following text: Arithmetic Mean: Calculate the geometric mean of the five numbers and output it on its own line using the following text: Geometric Mean: Calculate the harmonic mean of the five numbers and output it on its own line using the following text: Harmonic Mean:Explanation / Answer
/****complete and working code***/
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int i;
double a[5];
double biggest,smallest,am,gm,hm;
cout<<"Enter 5 positive numbers:";
cin>>a[0];
biggest=smallest=a[0];
for(i=1;i<5;i++){
cin>>a[i];
if(a[i]>biggest)biggest=a[i];
if(a[i]<smallest)smallest=a[i];
}
am=a[0]+a[1]+a[2]+a[3]+a[4];
am=am/5;
gm=a[0]*a[1]*a[2]*a[3]*a[4];
gm=pow(gm,1.0/5);
hm=(1/a[0])+(1/a[1])+(1/a[2])+(1/a[3])+(1/a[4]);
hm=hm/5;
cout<<"Biggest : "<<biggest<<endl;
cout<<"Smallest : "<<smallest<<endl;
cout<<"Arithmetic Mean : "<<am<<endl;
cout<<"Geometric Mean : "<<gm<<endl;
cout<<"Harmonic Mean : "<<hm<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.