Answer to Question #224818 in C++ for Sam

Question #224818

write a c++ program that calls for n values from a user and return the greatest among them


1
Expert's answer
2021-08-10T04:29:11-0400
//write a c++ program that calls for n values from a user and return the greatest among them
#include <iostream>
using namespace std;

int main()
{
    int a, n;
    float arr[90];
    //calls for n values from a user
    cout << "User enter the number of values(1 to 90): ";
    cin >> n;
    //cout << endl;

    // Store the values entered by the user
    for(a = 0; a < n; ++a)
    {
       cout << "Enter Number " << a + 1 << " : ";
       cin >> arr[a];
    }

    // Loop to store the greatest value to arr[0]
    for(a = 1;a < n; ++a)
    {
       // Change < to > if you want to find the least value
       if(arr[0] < arr[a])
           arr[0] = arr[a];
    }
    cout << "The greatest value among them is = " << arr[0];

    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