Create an array of size 10 fill the array from the user. Then ask the user for the order of sorting ascending or descending. And sort the array using bubble sorting algorithm.
#include <iostream>
using namespace std;
int main()
{
int Array[10];
cout << "Enter array elements using space (1 2): ";
for (int i = 0; i < 10; i++)
{
cin >> Array[i];
}
cout << endl << "Initial Array: ";
for (int i = 0; i < 10; i++)
{
cout << Array[i] << " ";
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 9; j++)
{
if (Array[j] > Array[j + 1])
{
int temp = Array[j];
Array[j] = Array[j + 1];
Array[j + 1] = temp;
}
}
}
cout << endl << "Sorted Array: ";
for (int i = 0; i < 10; i++)
{
cout << Array[i] << " ";
}
cout << endl;
system("pause");
return 0;
}
Comments
Leave a comment