write a program that calculate (minimum, maximum and average) of 10 entered numbers
______________________________________________________
#include<iostream.h>
int main()
{
int a[10],sum=0,max,min;
float avg;
cout<<"Enter the 10 numbers: ";
for(int i=0;i<10;i++)
{
cin>>a[i];
cout<<endl;
}
for(i=0;i<10;i++)
{
sum=a[i]+sum;
avg= (float) sum/10;
}
max=a[0];
min=a[0];
cout<<"The average = "<<avg<<endl;
for(i=0;i<9;i++)
{
for(i=0;i<9;i++)
{
if(a[i]>max)
max=a[i];
}
}
for(i=0;i<9;i++)
{
for(i=0;i<9;i++)
{
if(a[i]<min)
min=a[i];
}
}
cout<<"The max = "<<max<<endl<<"The min = "<<min<<endl;
return 0;
}
int main()
{
int a[10],sum=0,max,min;
float avg;
cout<<"Enter the 10 numbers: ";
for(int i=0;i<10;i++)
{
cin>>a[i];
cout<<endl;
}
for(i=0;i<10;i++)
{
sum=a[i]+sum;
avg= (float) sum/10;
}
max=a[0];
min=a[0];
cout<<"The average = "<<avg<<endl;
for(i=0;i<9;i++)
{
for(i=0;i<9;i++)
{
if(a[i]>max)
max=a[i];
}
}
for(i=0;i<9;i++)
{
for(i=0;i<9;i++)
{
if(a[i]<min)
min=a[i];
}
}
cout<<"The max = "<<max<<endl<<"The min = "<<min<<endl;
return 0;
}
No comments:
Post a Comment