I tried to bubble sort but when i output it, it gives me funky numbers. Can you help me out.
is the bubble sort even right?
#include <stdio.h>
int sort(int a[], int len)
{
int x, y, t;
for (x=0; x < len-1; x++)
{
for (y=0; y < len-x-1; y++)
{
if (a[y] > a[y+1])
{
t=a[y];
a[y]=a[y+1];
a[y+1]=t;
}
}
}
return t;
}
int main (void)
{
int i,x,a[10], len;
printf("len of array: ");
scanf("%d", &len);
for (x = 0; x < len; x++)
{
printf("Enter numbers: ");
scanf("%d",&a);
}
printf("Sorted array: \n");
for (i = 0; i < len; i++)
{ sort(a, len);
printf("%d ", a[i]);
}
}