- #include<iostream.h>
-
#include<conio.h>
-
void main() {
-
int num[10];
-
clrscr();
-
cout<<"ENTER NUMBERS TO SORT THEM IN ASCENDING ORDER & FIND THE AVERAGE"<<endl;
-
for(int times=0;times<=10;times++)
-
{
-
cout<<"Enter a number";
-
cin>>num[times];
-
}
-
for(int z=0;z<=10;z++)
-
{
-
cout<<"Ouput is : "<<num[z]<<endl;
-
}
-
getch();
-
}
There's one problem with your code. You start times and z at 0 to access elements of your array, but your end condition is <= 10 - you will try to access num[10] twice, which is out of bounds of the array.
How do you find the average of any set of numbers? You add them all together, then divide that total by the number of elements. Repeat this with your array, making sure to cast the element number to a double before dividing.
There are plenty of sorting algorithms out there, or you can make your own - since you have the numbers being entered one by one, every time a number is entered you can look for the proper place for that number to go.