When we have
list = 5 4 3 2 1
how to sort array in increasing order ? list = 1 2 3 4 5
here is process how I think
5 - 4 compare if greater then update 4 5 3 2 1
5 - 3 compare if greater then update 4 3 5 2 1
5 - 2 compare if greater then update 4 3 2 5 1
5 - 1 compare if greater then update 4 3 2 1 5
and so more
I wrote my program to sort array in increasing order
Code:
#include <stdio.h>
int main()
{
int i = 0; int j = 0; int k = 0;
int list[5] = {5, 4, 3, 2, 1};
int temp[5];
for (i = 0; i <5; i++)
{
for (j = i+1 ; j <5; j++)
{
if (list[i]>list[j]) // if the one is greater then other swap value
{
temp[k] = list[j];
list[i] = temp[k];
}
}
}
return 0;
}
What's wrong in code