-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex9.c++
53 lines (41 loc) · 980 Bytes
/
ex9.c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
@rofi
*/
/*min, max, sum, avg of n-numbers without using array*/
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int count, input, sum, max , min , avg;
cout<<"How Many Numbers:";
cin>>count;
cout<<"Input the numbers one by one";
for(int i=0; i<count; i++){
cout<<"\n Input "<<i+1<<"th Number: ";
cin>>input;
//initialize max and min for first input
if(i == 0){
min = input;
max = input;
}
//add to sum
sum +=input;
//if greater than the current maximum change max
if(input>max){
max = input;
}
//if less the current minimum change min
if(input<min){
min = input;
}
}
//calculate average
avg = float(sum/count);
//Display the results
cout<<"\n The Maximum is :"<<max
<<"\n The Minimum is :"<<min
<<"\n The Sum is :"<<sum
<<"\n The Average is :"<<avg
<<"\n";
return 0;
}