When I provide random unsorted input it breaks, when I give sorted or reverse sorted numbers it kind of works sometimes, I've checked for the algorithm I think it's correct, swapping when if condition is not satisfied.
#include <stdio.h>
int main()
{
int N=10,max,a[N];
printf("Enter the numbers:");
for(int i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<N;i++)
{
printf("%d,",a[i]);
}
printf("\n");
for(int i=0;i<N;i++)
{
for(int j=1;j<N;j++)
{
if (a[i]>a[i+j])
{
int temp=0;
temp=a[i+j];
a[i+j]=a[i];
a[i]=temp;
}
}
}
for(int i=0;i<N;i++)
{
printf("%d,",a[i]);
}
return 0;
}
OUTPUT
Enter the numbers:78
96
78
5
69
3
7
6
9
2
78,96,78,5,69,3,7,6,9,2,
2,-1847346713,3,5,0,6,7,9,69,78,