in C I have to use the void function in this code and call i

(in C++)

I have to use the void function in this code and call it in main to print the grades from int grades[] in descending order. this is what i have so far but i don\'t know what to do in the main function

#include<iostream>

using namespace std;

void sort(double x[], int n);
int main()
{
   int grades[] = { 100, 95, 87,92,79 };
  

   return 0;
}

void sort(double x[], int n)
{
   int m;
   double hold;
   for (int k = 0; k <= n - 2; ++k)
   {
       m = k;
       for (int j = k + 1; j <= n - 1; ++j)
           if (x[j] > x[m])
               m = j;
       hold = x[m];
       x[m] = x[k];
       x[k] = hold;
   }
   return;
}

Solution

#include using namespace std; void sort (int a[], int n) { for (int p = 0; p < n; ++p) for (int q = 0; j < n - p - 1; ++q) if (a[q] < a[q + 1]) { int t = a[q]; a[q] = a[q + 1]; a[q + 1] = t; } } int main() { int grade[] = {100, 85, 97, 85,92, 79}; int n = sizeof (grade) / sizeof (grade[0]); sort (grade, n); cout << \"Sorted Array : \" << endl; for (int p = 0; p < n; ++p) cout << grade[p] << \" \"; return 0; }
(in C++) I have to use the void function in this code and call it in main to print the grades from int grades[] in descending order. this is what i have so far

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site