Code:
#include <stdio.h>
#include <conio.h>
int main()
{ int x[100], i, j;
int temp=0;
for(i = 0; i < 5; i++)
scanf("%d", &x[i]);
// for(int i=1;i<5;i++)
for(i = 0; i < 4; i++) //for this sort, we stop the outer loop index counter at max - 1
{
for(j = i + 1; j < 5; j++) //stop at max index
{
if (x[i] < x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
for(i = 0; i < 5; i++) //removed duplicate declaration for i
printf("%3d",x[i]);
printf("\n\n\t\t\t press enter when ready");
getch();
return 0;
}
Although it's now standard to allow variables to be declared anywhere in the function, it's still a great idea, to declare them all at the top of the function. You won't double declare any, and you won't be hunting around trying to find out all the variable names you've declared. Because they're all together, already.
It wasn't sorting because you left out the second for loop.