Skip to main content

Bubble Sort in C

#include<stdio.h>
#include<conio.h>

void main()
	{
	clrscr();
	int i,j,n,t,DATA[50];
	printf("HOW MANY ELEMENT YOU WANT:\t");
	scanf("%d",&n);
	printf("START ENTERING VALUE..\n");
	for(i=1;i<=n;i++)
		{
		printf("DATA[%d]= ",i);
		scanf("%d",&DATA[i]);
		}
		/*start sorting BY ASSENDING ORDER..*/
	printf("\nDATA SORTED BY ASSENDING ORDER..");
	for(i=1;i<=n;i++)
		{
		for(j=i+1;j<=n;j++)
			{
			if(DATA[i]>DATA[j])
				{
				t=DATA[i];
				DATA[i]=DATA[j];
				DATA[j]=t;
				}
			}
		printf("\nDATA[%d]=%d",i,DATA[i]);
		}
		/*start sorting BY DISSENDING ORDER..*/
	printf("\nDATA SORTED BY DISSENDING ORDER..");
	for(i=1;i<=n;i++)
		{
		for(j=i+1;j<=n;j++)
			{
			if(DATA[i]<DATA[j])
				{
				t=DATA[i];
				DATA[i]=DATA[j];
				DATA[j]=t;
				}
			}
		printf("\nDATA[%d]=%d",i,DATA[i]);
		}
	getch();
	}

Spread the love

Mashkawat Ahsan

I am Mashkawat Ahsan. Wikipedian, Mozillian, tech activist, art lover. Thank you for visiting.

Leave a Reply

Your email address will not be published. Required fields are marked *