Hello,
I am trying to make a program which will sort a array of 10 elements using bubble sort. I searce dthe forum and google but douldnt find a problem similar to mine. I cam up with the following code:
#include <stdio.h>
#include <stdlib.h>
void swap(int *, int *);
int main()
{
int i, j, a[10];
for(i=0; i<10; i++)
{
printf("Enter Value %d: ", i);
scanf("%d", (a+i));
}
for(i=0; i<10; i++)
{
for(j=0;j<=9-i; j++)
{
if(a[j]>a[j+1])
{
swap(&a[j], &a[j+1]);
}
}
}
for(i=0; i<10; i++)
{
printf("%d ", *(a + i));
}
}
void swap(int *val1, int *val2)
{
int temp;
temp = *val1;
*val1 = *val2;
*val2 = temp;
}
However it was displaying the following output:
ATTACHED FILE\
Can anyone help me adress my problem