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.
#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]<<" ";
}
}
Comments
Leave a comment