Searching...
Saturday, 24 May 2014

PROGRAM IN LINUX C FOR BUBBLE SORT

5/24/2014 05:40:00 pm
#include<stdio.h>

  int main(){
  int s,temp,i,j,a[20];
  printf("Enter total numbers of elements: ");
  scanf("%d",&s);
  printf("Enter %d elements:\n",s);
  for(i=0;i<s;i++)
  {
      scanf("%d",&a[i]);
  }

 
  for(i=s-2;i>=0;i--){
      for(j=0;j<=i;j++){
           if(a[j]>a[j+1]){
               temp=a[j];
              a[j]=a[j+1];
              a[j+1]=temp;
           }
      }
  }

  printf("output :\n");
  for(i=0;i<s;i++)
      printf(" %d",a[i]);
printf("\n"); 
  return 0;


}

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.