Answer to Question #188733 in C++ for Asad

Question #188733

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. 



1
Expert's answer
2021-05-05T04:53:04-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS