Skip to content

Instantly share code, notes, and snippets.

@rohitrohan2009
Created March 16, 2017 09:18
Show Gist options
  • Save rohitrohan2009/44f6e0afa0b97dc605422d6882bd2c36 to your computer and use it in GitHub Desktop.
Save rohitrohan2009/44f6e0afa0b97dc605422d6882bd2c36 to your computer and use it in GitHub Desktop.
Bubble Sort program in C (no functions used)
//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