/* Bubble Sorting */
#include <stdio.h>
int main()
{
int n, i, j, temp;
printf("Enter the number of elements: ");
scanf("%d", &n);
int a[n];
for(i = 0; i < n; i++){
printf("Enter element %d: ", i+1);
scanf("%d", &a[i]);
}
printf("Array you entered is .....\n");
for(i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\nArray in ascending order is .....\n");
for(i = 0; i < n; i++){
for(j = i+1; j < n; j++){
if(a[j] < a[i]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
printf("%d ", a[i]);
}
return 0;
}
Comments
Post a Comment