#include <stdio.h> #include <stdlib.h> void bsort (int arr[ ],int n) { int i,j; int tmp; for (i=0;i<(n-1);i++){ for (j=0;j<(n-i-1);j++){ if(arr[j]>arr[j+1]){ tmp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=tmp; } } } printf("The Numbers Sorted :\n"); for (i=0;i<n;i++){ printf("%d\n",arr[i]); } } int main() { int arr[100]; int i=0; int n; printf("Enter the number of the array\n"); scanf("%d",&n); printf("Please enter array integers numbers !\n"); for (i=0;i<n;i++){ scanf("%d",&arr[i]); } printf("\n\n"); bsort(arr,n); return 0; }
Output Sample :
0 Comment to "Bubble Sort"
Post a Comment