clanguage07@gmail.com

clanguage07@gmail.com

Sunday, September 8, 2013

BUBBLE SORT USING C PROGRAM




Source code of simple bubble sort implementation using array ascending order in c programming language
#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: ",s);
  for(i=0;i<s;i++)
      scanf("%d",&a[i]);
  //Bubble sorting algorithm
  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("After sorting: ");
  for(i=0;i<s;i++)
      printf(" %d",a[i]);
  return 0;
}

Output:
Enter total numbers of elements: 5
Enter 5 elements: 6 2 0 11 9
After sorting:  0 2 6 9 11




5. Write a c program for heap sort.
7. Write a c program for shell sort.

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true