Bubble sorting – C Program

Bubble sorting – C Program

write a c program to accept array from user and sorting element using bubble sort method.

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

void main()
{
 int arr[30],i,j,temp,no
printf("Enter size of array=\n");
scanf("%d",&no);

 printf("\nPlease enter Elements of Array =\n");
 for(i=0;i<no;i++)
  {
   scanf("%d",&arr[i]);
  } 
 for(i=0; i<no; i++)
 {
  for(j=0; j<no-i; j++)
  {
   if (arr[j] > arr[j+1])
   {
    temp=arr[j];
    arr[j]=arr[j+1];
    arr[j+1]=temp;
   }
  }
 }
 
printf("The Sorted Array is = \n");
 for(i=0;i<no;i++)
 {
  printf("%d\t",arr[i]);
 } 
getch();
}

The output of bubble sort c program is:

Enter size of array =
8

Please enter Elements of Array =
6

3
4
2
5
8
7
1
6

The Sorted Array is =
1 2 3 4 5 6 7 8

 

Author: Meera Academy

Leave a Reply

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