Skip to main content

BUBBLESORT

Q1: Write a C program for BubbleSort ?


#include<conio.h>                                        
#include<stdio.h>                                         
void main()                                                    
{                                                                     
int i,j,n,tmp,a[20];                                           
clrscr();                                                          
//Intialising Array 
printf("\nEnter the number of elements--\t");  
scanf("%d",&n);                                              
printf("\nThe Elements are----\n");                  
for(i=0;i<n;i++){                                               
scanf("%d",&a[i]);}                                          
//Bubble Sort Algorithm  
                               
for(i=1;i<n;i++)                                                
{                                                                      
for(j=0;j<n-i;j++)                                              
{                                                                     
//Ascending Order
if(a[j]>a[j+1]){                                                 
tmp=a[j];                                                        
a[j]=a[j+1];                                                      
a[j+1]=tmp;                                                    
}                                                                     
}                                                                    
}                                                                     
//Output 
printf("After BubbleSort\n");                            
for(j=0;j<n;j++)                                               
{                                                                     
printf("%d\t",a[j]);                                           
}                                                                     
getch();                                                          
}                                                                      


***********************************************************************************

Sample Output:





Comments

Popular posts from this blog

CAREER OPTIONS AFTER BCA

Career Options after BCA There are several doors opened, once you are done with your bachelor's in computer application(BCA).Apart from MCA or MBA in IT , one can also go for :  Masters in Computer Management  Masters Degree in Information Management (MIM)  Master of Science in Information Technology (M.Sc IT)  G-CAT Master  Postgraduate Diploma in Computer Applications  Post Graduate Program in Corporate Studies (PGPCS)  Postgraduate Diploma in Management (PGDM)  Program in Information Security Management  If one wants to get recruited and desires to be the part of corporate sector....there are numerous options for that too. One can work as a software developer, web developer, graphic Designer, App Developer for

LIST OF PROGRAMS

Practical Lab Quadratic   Bisection  False position  Newton raphson  Birgei vieta    Soln. of simultaneous linear equation   Gauss seidal method    Interpolation    Construct a diff. Table (forward /backward /divided)   Any one -  Newton Forward   Newton Backward   Newton Divided   Lagrange   Integration   Find integral value using - Simpsons ⅓  Simpsons ⅜  Statistics   Mean (AM) - any series - step deviation  Dispersion- md/sd  Correlation Coefficient  Regression lines

ABOUT US

--------------- About Us ---------------- The Blog offers information and notes on the class subjects, instructed by the teacher and written by me. I have made this blog for the students who are for any reason are unable to attend the class. This will be an easy platform for them to get their class work and do it at anytime, anywhere and at their pace.   In this era of technology with just an internet connection, you can do anything and rely on this platform for your class work. Contacts Us: Facebook ID:  bcahubsd Email-  bcahubsd@gmail.com editor@bcahubsd.com