0% found this document useful (0 votes)
25 views

Program of Bubble Sort in Array

This program implements bubble sort to sort an integer array in ascending order. It prompts the user to enter the size of the array and its elements. It then performs multiple iterations of the bubble sort algorithm, swapping adjacent elements if out of order and printing the array after each iteration. Finally, it prints the sorted array.

Uploaded by

Suman Lata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Program of Bubble Sort in Array

This program implements bubble sort to sort an integer array in ascending order. It prompts the user to enter the size of the array and its elements. It then performs multiple iterations of the bubble sort algorithm, swapping adjacent elements if out of order and printing the array after each iteration. Finally, it prints the sorted array.

Uploaded by

Suman Lata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*PROGRAM OF BUBBLE SORT IN ARRAY*/

#include<iostream.h> #include<conio.h> void BubbleSort(int[],int); void main() { int AR[50],N; clrscr(); cout<<"How many elements do you want to create Array with?(max.50)..."; cin>>N; cout<<"\nEnter Array Elements...\t"; for(int i=0;i<N;i++) cin>>AR[i]; } BubbleSort(AR,N); cout<<"\n\nThe Sorted Array is as shown below...\n"; for(i=0;i<N;i++) cout<<AR[i]<<"\n"; cout<<endl; void BubbleSort(int AR[],int size) int tmp,ctr=0; for(int i=0;i<size;i++) for(int j=0;j<(size-1)-i;j++) if(AR[j]>AR[j+1]) tmp=AR[j]; AR[j]=AR[j+1]; AR[j+1]=tmp; cout<<"Array after iteration-"<<ctr++<<"-is:\t"; for(int k=0;k<size;k++) cout<<AR[k]<<" "; cout<<endl; } }

} { { { { }

OUTPUT
How many elements do you want to create Array with?(max.50)... 4 Enter Array Elements... 7 3 8 2 Array after iteration-1-is: 3 7 8 2 Array after iteration-2-is: 3 7 8 2 Array after iteration-3-is: 3 7 2 8 Array after iteration-4-is: 3 7 2 8 Array after iteration-5-is: 3 2 7 8 Array after iteration-6-is: 2 3 7 8 The Sorted Array is as shown below... 2 3 7 8

You might also like