I have been trying to get this working for the past 3 hours, trolling on forums and I am in fact lost. Any help would be appreciated...I think I got lost with all my stupid variables. I am trying to get the average for my arrays, I got the ascending order to work finally and do not really want to go back because that took me forever...All I want to do is to be able to take the numbers from within the array and output them with an average...any help is MUCH appreciated, thanks again for your time.
Code:
Code:
#include <conio.h>
#include <stdio.h>
int main()
{
int data[100],i,n,step,temp,sum;
printf("Enter the number of elements to be sorted: ");
scanf("%d",&n); //scans input and puts into integer n
for(i=0;i<n;++i)
{
printf("%d. Enter element: ",i+1);
scanf("%d",&data[i]);
}
for(step=0;step<n-1;++step)
for(i=0;i<n-step-1;++i)
{
if(data[i]>data[i+1]) //sorts in ascending order
{
temp=data[i];
data[i]=data[i+1];
data[i+1]=temp;
}
}
printf("In ascending order: ");
for(i=0;i<n;++i)
printf("%d ",data[i]);
sum=0; //this is the part that I amm lost on...I understand its wrong my brain is just fried and need a second set of eyes..
for(i=0;i<n;++i);
sum=sum+i/n;
printf("Average is %d\n", sum);
getch(); //
return 0;
}