Answer to Question #237746 in C++ for scada HMI

Question #237746

Declare an array ‘list’ of length 15.

• Input the values from user.

• Pass that array to a function sorting.

• Your function should only accept a pointer as an argument.

• Sort the values of the array in ascending order using any of the sorting techniques.


1
Expert's answer
2021-09-15T23:39:26-0400


#include <iostream>


using namespace std;
void sort(int *arr){
    int temp;
    for (int i = 1; i < 15; i++) {
        for (int j = i; j > 0; j--) {
            if (arr[j] < arr [j - 1]) {
              temp = arr[j];
              arr[j] = arr[j - 1];
              arr[j - 1] = temp;
     }
    }
   }
   for (int i = 0; i < 15; i++) {
     cout<<"\n"<<arr[i];
   }
}
int main()
{
    int list[15]; //Declare an array ‘list’ of length 15.
    //Input the values from user.
    cout<<"\nEnter 15 integers:\n";
    for(int i=0;i<15;i++){
        cin>>list[i];
    }
    sort(list);
    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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS