Computer Science, asked by joglekaraashay, 17 days ago

Ctt Write a C++ program to accept 8 numbers in an arkay. Sort the numbers in ascending order using Bubble sort method. Also insert a number in the sorted sorted array.​

Answers

Answered by samarthkrv
0

Answer:

#include <iostream>

using namespace std;

void bubble_sort(int arr[] , int n){

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

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

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

               int temp = arr[i];

               arr[i] = arr[j];

               arr[j] = temp;

           }

       }

   }

}

void printArray(int arr[] , int n){

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

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

   }

}

int main()

{

int len;

int arr[len];

cout<<"Enter the length of the array:";

cin>>len;

for(int i = 0; i < len; i++){

   cin>>arr[i];

}

cout<<"BEFORE SORTING- \n";

printArray(arr,len);

cout<<"AFTER SORTING- \n";

bubble_sort(arr,len);

printArray(arr,len);

return 0;

}

Explanation:

Similar questions