Answer to Question #313511 in C++ for Hassan

Question #313511

Declare an array arr1 of length 10.

• Input the values from user.

• Pass that array to a function sorting.

• Your function should take a pointer as an argument.

• Sort the values of the array in ascending order in sorting.


1
Expert's answer
2022-03-17T17:09:55-0400
#include <iostream>

using namespace std;


void SwapInt(int* x, int* y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}

void Sorting(int* arr)
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10 - i - 1; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				SwapInt(&arr[j], &arr[j + 1]);
			}
		}
	}
}

int main()
{
	int arr[10];
	cout << "Please, enter an elements of array: "<<endl;
	for (int i = 0; i < 10; i++)
	{
		cout << "Enter a value of array[" << i << "]: ";
		cin >> arr[i];
	}
	Sorting(arr);
	for (int i = 0; i < 10; i++)
	{
		cout << arr[i]<<" ";
	}
}

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
New on Blog