03 March 2026

Bubble Sort

 #include<stdio.h>

#include<conio.h>


void main()

{

int a[99],i,j,temp,no;

printf("\n Enter the max no.of Elements to Sort: \n");

scanf("%d",&no);

printf("\n Enter the Elements : \n");

for(i=0; i<no; i++)

{

scanf("%d",&a[i]);

}

for(i=0; i<no; i++)

{

for(j=i+1; j<no; j++)

{

if(a[i]>a[j])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

for(i=0; i<no; i++)

{

printf("%d\t",a[i]);

}


getch();

}

No comments:

Post a Comment