In this C please do use stdioh In function main prompt a use
In this C++ please do use stdio.h
In function main, prompt a user to enter 5 numbers into an integer array.
When done entering print the original array to the screen.
Call a function that will sort the array from largest to smallest(using the algorithm we developed in class) and return the sorted array to main.
Print the sorted array to the screen.
Solution
#include<iostream>
using namespace std;
int main()
{
int a[5];
cout<<\"enter 5 integers :\";
for(int i=0;i<5;i++)
{
cin>>a[i];
}
cout<<\"array elements are:\ \";
for(int i=0;i<5;i++)
{
cout<<a[i]<<\"\ \";
}
int b[5];
b=sortArr(a);
cout<<\"\ sort3d elements are\ \";
for(int i=0;i<5;i++)
{
cout<<b[i]<<\"\\t\";
}
return 0;
}
int[] sortArr(int a[])
{
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
return a;
}
