C Program To Implement Bubble Sort Algorithm To Print N Numbers In Ascending Order
♣ Try it Out ::
#include<stdio.h> #include<conio.h> void BubbleSort(int*, int); int main() { int ArraySize; printf("How many numbers you wish to enter: "); scanf("%d", &ArraySize); int Array[ArraySize], i; printf("Enter %d integers: \n", ArraySize); for(i=0; i<ArraySize; i++) scanf("%d", &Array[i]); BubbleSort(Array, ArraySize); printf("\nSorted list in ascending order:\n"); for(i=0; i<ArraySize; i++) printf("%d ", Array[i]); getch(); return(0); } void BubbleSort(int Arr[], int Size) { int Swap, i, j; for(i=0; i<Size-1; i++) for(j=Size-1; j>=i+1; j--) if(Arr[j-1] > Arr[j]) { Swap = Arr[j-1]; Arr[j-1] = Arr[j]; Arr[j] = Swap; } }
♣ Output ::
How many numbers you wish to enter: 5 Enter 5 integers: 8 0 1 9 7 Sorted list in ascending order: 0 1 7 8 9
♣ Downloads ::
Comments
Post a Comment