write a c++ program that calls for n values from a user and return the greatest among them
//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;
}
Comments
Leave a comment