Computer Science, asked by jg63050, 7 months ago

Variable Description is required to be written.
Write a program to accept 20 integers in a single dimensional array and sort the array
elements in descending order using bubble sort technique. Print the unsorted as well as sorted
array separately.
Answer​

Answers

Answered by mansisehga
1

#include<iostream>

using namespace std;

int main ()

{

int i, j,temp,pass=0;

int a[10] = {10,2,0,14,43,25,18,1,5,45};

cout <<"Input list ...\n";

for(i = 0; i<10; i++) {

cout <<a[i]<<"\t";

}

cout<<endl;

for(i = 0; i<10; i++) {

for(j = i+1; j<10; j++)

{

if(a[j] < a[i]) {

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

pass++;

}

cout <<"Sorted Element List ...\n";

for(i = 0; i<10; i++) {

cout <<a[i]<<"\t";

}

cout<<"\nNumber of passes taken to sort the list:"<<pass<<endl;

return 0;

}

Output:

Input list …

10 2 0 14 43 25 18 1 5 45

Sorted Element List …

0 1 2 5 10 14 18 25 43 45

Number of passes taken to sort the list:10

Similar questions