Write a program that sorts an array ‘ABC’ in ascending order using Bubble Sort method. The array consists of N elements.
So let’s Write Code:
Code:
Write a program that sorts an array ‘ABC’ in ascending order using the Bubble Sort method. The array consists of N elements.
#include<iostream>
using namespace std;
main()
{
int ABC[10], i, u, temp;
i = 0;
while(i<=9)
{
cout<<"Enter value for element "<<i<<"? ";
cin>>ABC[i];
i++;
}
u = 9;
while(u>=1)
{
i = 0;
while(i<u)
{
if(ABC[i] > ABC[i+1])
{
temp = ABC[i];
ABC[i] = ABC[i+1];
ABC[i+1] = temp;
}
i++;
}
u--;
}
cout<<"\nValues of array ABC in ascending order\n";
for(i = 0; i<=9; i++)
cout<<ABC[i]<<" ";
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/