In: Computer Science
In C++, Write a program that accepts exactly ten (10) integer numbers from the user. When the user is done inputting these numbers, the program prints back: (i) the sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value from the 10 numbers.
Below is the c++ solution with output screenshot
Code :
// including libraries
#include <iostream>
using namespace std;
// main function
int main()
{
// declaring an array which will store all 10 numbers
int num[10];
cout<<"Enter 10 Numbers :\n";
// take input 10 numbers
for(int i=0;i<10;i++)
{
cin>>num[i];
}
// declare and initialize variables
int sum = 0;
int min = num[0];
int max = num[0];
// sum all the 10 numbers
// if the current value is smaller make that minimum
// if the current value is bigger then make take maximum
// do this for all the 10 numbers
for(int i=0;i<10;i++)
{
sum += num[i];
if(num[i]>max){
max = num[i];
}
if(num[i]<min){
min = num[i];
}
}
// output the result
cout<<"Sum = "<<sum<<endl;
cout<<"Minimum = "<<min<<endl;
cout<<"Maximum = "<<max<<endl;
return 0;
}
Output :
Note : for better formatting please refer to the code screenshot below