Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Bubble sort

Posted By: Layla Hughes     Category: C Programming     Views: 6204

Write a program of bubble sort.

Code for Bubble sort in C Programming

#include<stdio.h>
#include<conio.h>
#define N 6

void main()
{
    int arr[N]={0};
    int key,exch=0,pass,comp,temp,i;


    textcolor(00);
    textbackground(55);

    clrscr();


    printf("\n\t ENTER THE DATA::: ");
    for(i=0;i<N;i++)
    {
        scanf("%d",&arr[i]);
    }

    for(pass=0;pass<N;pass++)
    {
        clrscr();
        printf("\n\t PASS::: %d",pass+1);

        for(comp=0;comp<N;comp++)
        {
            printf("\n COMP ::: %d.%d",pass+1,comp+1);
            if(arr[comp]>arr[comp+1])
            {
                exch=1;
                temp=arr[comp];
                arr[comp]=arr[comp+1];
                arr[comp+1]=temp;
            }
            printf("\n\t\t %d",arr[comp]);
        }
        printf("\n\t");
        getch();
     }
     printf("\n\n\t DATA AFTER SORTING......");
     printf("\n\n\n");

     for(i=0;i<N;i++)
     {
        printf("\t %d",arr[i]);
     }
     getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Bubble sort Or get search suggestion and latest updates.

Layla Hughes
Layla Hughes author of Bubble sort is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!