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
Write a C program to input five numbers and print them out on a new line e.g 5, 10, 15, 20, 25 displayed as   5   10   15   20   25 #include stdio.h   void main()   {

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw .

1. The management of a company would like to determine the median annual salary of its employees.Write a pascal program that display the number of employees and their median salary

(a) client server or multithreaded client-server, where server will create pool of worker threads (say 5) to provide services to pool of clients (say 5 ).Server should be behaving

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

flow chart for push operation in stack

Define the Keywords of c language? C keeps a small set of keywords for its personal use. These keywords can't be used as identifiers in the program. Here is the list of keyword

Question 1 Explain the following Object Oriented Concepts with suitable examples for each Question 2 Explain the following Object Oriented Methodologies Question 3 Descr


# include stdio.h> # include conio.h> # include math.h>   void main () { int a=1,sqr=0,cube=0; clrscr (); while (a { sqr=pow(a,2); cube=pow(a,3);