-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1.cpp
More file actions
42 lines (37 loc) · 922 Bytes
/
Copy pathex1.cpp
File metadata and controls
42 lines (37 loc) · 922 Bytes
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
#include <iostream>
#include <ctime>
#include <cstdlib>
int main(){
const int n = 10;
int a[n];
srand((unsigned) time(nullptr));
for(int i = 0; i < n; i++) a[i] = rand()%n;
double mean( int [],int);
int max( int [],int);
int min( int [],int);
using namespace std;
for(int i = 0; i < n; i++)
cout << a[i] << ' ' ;
cout << endl;
cout << "mean: " << mean(a,n) << endl;
cout << "max: " << max(a,n) << endl;
cout << "min: " << min(a,n) << endl;
}
double mean(int a[],int n){
int len = n;
int sum = 0;
for(int i = 0; i < len; i++) sum += a[i];
return (double)sum/len;
}
int max(int a[],int n){
int len = n;
int tmp = a[0];
for(int i = 1; i < len; i++) if(a[i] > tmp) tmp = a[i];
return tmp;
}
int min(int a[],int n){
int len = n;
int tmp = a[0];
for(int i = 1; i < len; i++) if(a[i] < tmp) tmp = a[i];
return tmp;
}