Take (10) integers, store them in 1D array then do the following:
1. find the max and min number of them
2. find the average
3. sort these numbers in ascending squence
the first two questions are quite easy but my problem is in sorting those numbers...anyways, i came up with this code:
#include<iostream.h>
void main()
{
int a[10],max,min,sum=0;
int temp,j;
float average;
for(int i=0;i<10;i++)
cin>>a[i];
max=a[0];
min=[0];
for(i=0;i<10;i++)
{
if(a[i]>max)
max=a[i];
else
if(a[i]<min)
min=a[i];
sum+=a[i];
}
for(i=0,j=9;i<5,j>4;i++,j--)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
cout<<"ascending order:\n";
for(i=0;i<10;i++)
cout<<a[i]<<endl;
average=sum/10.0;
cout<<"max:"<<max<<endl;
cout<<"min:"<<min<<endl;
cout<<"average:"<<average;
}
after running the progam i entered 10 9 8 7 6 5 4 3 2 1, for instance ... the output was :
1 2 3 4 5 6 7 8 9 10 ..which is correct
but when i entered random numbers .. 34 52 78 100 77 53 37 99 100 143 .... the output was missed up and incorrect .....so can somebody help plz?