write a program which inputs five numbers and displays
1. the minimum number
2. the maximum number
3. average of numbers
4. average of minimum and maximum numbers
5. difference between average and average of minimum and maximum numbers
sample output:
enter five numbers: 45 43 23 21 56
minimum number is: 21
maximum number is: 56
average of minimum and maximum numbers: 38.5
difference between average and average of minimum and maximum numbers: 0.9
1
Expert's answer
2012-10-18T10:54:11-0400
#include "iostream" using namespace std;
short i; float a[5], min, max, avm, ave=0;
void main(){ cout<<"enter five numbers: "; cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]; min = max = a[0]; for (i=1;i<5;i++){ & if (min>a[i]) min = a[i]; & if (max<a[i]) max = a[i]; & ave += a[i]; } cout<<"minimum number is: "<<min<<"\n"; cout<<"maximum number is: "<<max<<"\n"; avm = (max+min)/2; cout<<"average of minimum and maximum numbers: "<<avm<<"\n"; cout<<"difference between average and average of minimum and maximum numbers: "<<abs(ave/5-avm)<<"\n"; system("PAUSE"); }
Comments
Leave a comment