``````#include<stdio.h>
#include<conio.h>
main()
{
clrscr();

double sales[10];
int index;
double largestsale,smallestsale,sum,average;

//initializing
for(index=0;index<5;index++)
sales[index]=0.0;

printf("Enter Value:\n");
for(index=0;index<5;index++)
scanf("%d",&sales[index]);

//printing
for(index=0;index<5;index++)
if(sales[index]<index)
printf("%2d",sales[index]);

//sum & average
sum=0;
for(index=0;index<5;index++){
sum = sum+sales[index];}
average = sum/5;

printf("\nThe Sum is %d",sum);
printf("\nThe Average is %d",average);

//largestsale
int maxIndex = 0;
for(index=1;index<5;index++)
if(sales[maxIndex] < sales[index])
maxIndex = index;
largestsale = sales[maxIndex];
printf("\nLargestsale is %d",largestsale);

//smallestsale
int minIndex = 0;
for(index=1;index<5;index++)
if(sales[minIndex] > sales[index])
minIndex = index;
smallestsale = sales[minIndex];
printf("\nSmallestsale is %d",smallestsale);

getch();
return 0;
}``````

## All 5 Replies

Is there a question in there somewhere?

how to sort array

can you help me? what variables am i going to plus and minus?

what variables am i going to plus and minus?

If you are sorting, you are not adding or subtracting anything. Sort your array in place. Here's one pass through the data(sorting in ascending order):

``````|6|3|5|9|2|
is 6 > 3, yes, so swap those elements
|3|6|5|9|2|
is 6 > 5, yes, so swap those elements
|3|5|6|9|2|
is 6 > 9 no, so leave the element alone
|3|5|6|9|2|
is 9 > 2 yes, so swap those elements
|3|5|6|2|9|``````

Since we know that element0 is going to be sorted with respect to element1, start at element1 and repeat the above process. As we go over the list iteration after iteration, that 2 will percolate down to the bottom. That site I gave you is great because it shows you animations. See if you can make some C code out of the pseudocode they provide there along with the details above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.