Answer to Question #286422 in C++ for Roe

Question #286422

Write a C++ program that creates an array of 10


elements. The program should then take input in the


array from the user. After that, the program sorts the


array elements in descending order. The sorting code


should access array elements using pointer notation

1
Expert's answer
2022-01-11T02:16:19-0500
#include <iostream>
using namespace std;
int main(){
    int array[10];
    cout<<"Input 10 integers\n";
    for(int i = 0; i < 10; i++)
        cin>>array[i];
    
    for(int i = 0; i < 10; i++){
        for(int j = i + 1; j < 10; j++){
            if(*(array + j) > *(array + i)){
                int temp = *(array + i);
                *(array + i) = *(array + j);
                *(array + j) = temp;
            }
        }
    }


    cout<<"Sorted in descending order\n";
    for(int i = 0; i < 10; i++)
        cout<<array[i]<<" ";
    cout<<"\n";
    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