Computer Science, asked by maityavijit4208, 9 months ago

Write a program to enter 10 integers in an array sort them in ascending order by using bubble sort technique and print the

sorted array.​

Answers

Answered by kumarraja2k05
3

Answer:

bubble sort

Explanation:

#include<iostream>

using namespace std;

int main(){

 int arr[20];

 int n,i;

 cout<<"enter the value of n";

 cin>>n;

 cout<<"enter the array element";

 //entering the array elements

 for(i=0;i<n;i++)

 {

     cin>>arr[i];

 }

 int k;

 // performing sorting

 for(i=0;i<n-1;i++)

 {

     for(int j=0;j<n-i-1;j++){

     if(arr[j]>arr[j+1]){

        k=arr[j];

       arr[j]=arr[j+1];

       arr[j+1]=k;

     }}

 }

 //final array after sorting

 cout<<"after sorting:"<<endl;

 for(i=0;i<n;i++)

 {

     cout<<arr[i]<<"  ";

 }

}

Similar questions