62 499
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #55971 in C++ for rishabh

Question #55971
write a programme that will read 10 integers from user and store them in an array .implement array using pointer and print array element in ascending and descending order.
Expert's answer
Solution
#include <iostream>
#include <math.h>
#define N 10

using namespace std;
int main(int argc, char **argv)
{
int *arr=new int[N];
int i;
for(i=0;i<N;i++)
{
cout<<"Input element #"<<i<<": ";
cin>>arr[i];
}

//ordering
int imin,j;
for(i=0;i<N;i++)
{
imin=i;
for(j=i+1;j<N;j++)
if(arr[j]<arr[imin])
imin=j;
j=arr[imin];
arr[imin]=arr[i];
arr[i]=j;
}

//output:
cout<<"In ascending order: ";
for(i=0;i<N;i++)
cout<<arr[i]<<" ";

cout<<endl<<"In descending order: ";
for(i=0;i<N;i++)
cout<<arr[N-i-1]<<" ";
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions