Write a program that loads several numbers from the keyboard,
asking in the meantime, the question "Do you want to finish: Y / N?"
At the end of the loop, program should display calculated values of:
the arithmetic average, maximum, minimum of given numbers.
#include <iostream>
using namespace std;
int main()
{
int arr[100];
int n=0;
cout<<"\nEnter several numbers: ";
while(true){
int num;
cin>>num;
arr[n]=num;
char c;
cout<<"\nDo you want to finish: Y / N?";
cin>>c;
if (c=='Y'){
break;
}
n++;
}
int min=arr[0];
int max=arr[0];
int sum=0;
for(int i=0;i<n;i++){
if(arr[i]>max)
max=arr[i];
if(arr[i]<min)
min=arr[i];
sum+=arr[i];
}
cout<<"\nMaximum number: "<<max;
cout<<"\nMinimum number: "<<min;
cout<<"\nAverage number: "<<(sum/n);
return 0;
}
Comments
Leave a comment