write a program that input a series of 500 numbers in ID array later find and display the minimum values and maximum values and average of all numbers
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int arr[500];
int max, min, S;
srand(55);
for (int i = 0; i < 500; ++i)
{
arr[i] = rand();
}
cout << "Array: ";
S = 0;
max = min = arr[0];
for (int i = 0; i < 500; ++i)
{
cout << arr[i] << " ";
S += arr[i];
if (min > arr[i])
{
min = arr[i];
}
if (max < arr[i])
{
max = arr[i];
}
}
cout << "\nMinimum values: " << min << endl;
cout << "Maximum values: " << max << endl;
cout << "Average of all numbers: " << S << endl;
return 0;
}
Comments
Leave a comment