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.