Bubble sort c program, C/C++ Programming

Bubble sort C program:

Write a program to define a bubble sort.

void main()

 {

  clrscr();

  int a[100],ch,n;

  cout<<"enter the limit for the array : ";

  cin>>n;

  for (int i=0;i

                {

                cout<<"enter element "<

                cin>>a[i];

                }

                clrscr();

                cout<<"1. bubble sorting"<

                bsort(a,n);

                 }

 }

 

void bsort(int a[100],int n)

 {

   clrscr();

   int i,j,ch2,t;

   cout<<"1. ascending order "<

   cout<<"2. descending order "<

   cout<<" your choice : ";

   cin>>ch2;

   switch(ch2)

                {

                case 1 : for (i=0;i

                                                 {

                                 for (j=0;j

                                                {

                                                if (a[j] > a[j+1])

                                                {

                                                t=a[j+1];

                                                a[j+1]=a[j];

                                                a[j]=t;

                                                }

                                                }

                                 }

                                 break;

                case 2 : for (i=0;i

                                 {

                                 for (j=0;j

                                                {

                                                if (a[j] < a[j+1])

                                                {

                                                t=a[j+1];

                                                a[j+1]=a[j];

                                                a[j]=t;

                                                }

                                                }

                                 }

                                 break;

   default : cout<<" wrong choice ";

                }

                 cout<<" sorted arrays by bubble "<<"\n\n";

                 for (i=0;i

                  {

                  cout<

                  }

                  getch();

 

  }

Posted Date: 10/19/2012 3:11:09 AM | Location : United States







Related Discussions:- Bubble sort c program, Assignment Help, Ask Question on Bubble sort c program, Get Answer, Expert's Help, Bubble sort c program Discussions

Write discussion on Bubble sort c program
Your posts are moderated
Related Questions

What is Virtual Destructor? Describe it.


Create Complex number using constructor: class complex                                 {                                                   private:

I am doing project on home stay which includes features like add homestay,search,book,delete homestay,

Define the Logical Operators in c language? The Logical operators deals with the ways the relationships are able to connected. C has the following three logical operators

Call by reference: Arguments to a function can be passed in two way; one by call by value and other by call by reference.  Call by value is passed either through a constant

HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . ALSO HOW I CAN A BECOME A GOOD PROGRAMMER IN C WHAT I DO FOR GOOD PROGRAMMING ,TELL ME HOW C CODING DEVELOP DY ITSELF

In rPeANUt implement the "char getchar()" and "void printstring(char *str)" functions. Using these functions implement the following: void main() {    while (1) {       ch

Program for Hangman Problem   #include   #include   #include   #include   #include   static void playGame();   static void printMistakes(int n);   st