C Program For Sorting Array elements (Bubble sort)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],n,t;
clrscr();
printf("enter the value of n: ");
scanf("%d",&n);
printf("\nenter the values");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
 for(j=0;j<n-1;j++)
 {
  if(a[j]>a[j+1])
  {
   t=a[j];
   a[j]=a[j+1];
   a[j+1]=t;
  }
 }
}
printf("\nelements after bubble sorting are:\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}


Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment