Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Showing posts with label bubble sort. Show all posts
Showing posts with label bubble sort. Show all posts

Thursday, 24 October 2013

[C Program] To Implement Program for Bubble sort

//Program for Bubble sort

#include<stdio.h>
#include<conio.h>
//Main function
void main()
{
int i,a[10],n,j,temp;
clrscr();
printf("\nEnter the size of array:");
scanf("%d",&n);
printf("\n\nEnter the elements into array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEntered array:  ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]>a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\nSorted list:    ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}//end of main

/*Output

Enter the size of array:7

Enter the elements into array:12 88 5 100 32 77 50

Entered array:  12      88      5       100     32      77      50

Sorted list:    5       12      32      50      77      88      100 */

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine