Created
February 17, 2016 13:15
-
-
Save 78526Nasir/6aba35e87e2434259944 to your computer and use it in GitHub Desktop.
Bubble Sort Implementation In C using Array !
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
/// Bubble sort /// | |
#include<stdio.h> | |
main() | |
{ | |
int a[100],i,p,n,temp; | |
printf("Enter how many elements for your Array:"); | |
scanf("%d",&n); | |
printf("\nEnter %d values :",n); | |
for(i=0;i<n;i++) | |
scanf("%d",&a[i]); | |
printf("\nAscending to Descending "); | |
for(p=0;p<n-1;p++) | |
{ | |
for(i=0;i<n-1-p;i++) | |
{ | |
if(a[i]>a[i+1]) | |
{ | |
temp=a[i]; | |
a[i]=a[i+1]; | |
a[i+1]=temp; | |
} | |
} | |
} | |
printf("\n\n"); | |
for(i=0;i<n;i++) | |
printf("%d ",a[i]); | |
printf("\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment