Created
March 16, 2017 09:18
-
-
Save rohitrohan2009/44f6e0afa0b97dc605422d6882bd2c36 to your computer and use it in GitHub Desktop.
Bubble Sort program in C (no functions used)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CODE OF BUBBLE SORT// | |
#include"stdio.h" | |
main() | |
{ | |
int x, i , j, n,temp, arr[100]; | |
printf("Enter the number of arrays you want"); | |
scanf("%d", &n); | |
printf("Now enter the numbers: \n "); | |
for(i=0;i<n;i++) | |
{ | |
scanf("%d", &arr[i]); | |
} | |
printf("This is the array you just typed"); | |
for(i=0;i<n;i++) | |
{ | |
printf("\n%d", arr[i]); | |
} | |
printf("\nNow getting to the BUBBLE SORT CODE"); | |
for(i=0;i<n;i++) | |
{ | |
for(j=0;j<(n-i-1);j++) | |
{ | |
if(arr[j]>arr[j+1]) | |
{ | |
temp=arr[j]; | |
arr[j]=arr[j+1]; | |
arr[j+1]=temp; | |
} | |
} | |
printf("This is your ascending order result"); | |
for(i=0;i<n;i++) | |
{ | |
printf("\n%d", arr[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment