vector sn

 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
54
// Vector.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <vector>
using namespace std;
const int n = 10;
void Input(vector <int> &);
void SearchAv(vector <int> &);
float average(int, int);
int _tmain(int argc, _TCHAR* argv[])
{
vector <int> one;
int number;
Input(one);
SearchAv(one);
_getch();
return 0;
}
float average(int a, int b)
{
return (a+b) / 2;
}
void Input(vector <int> & one)
{
int tmp;
for (int i = 0; i < n; i++)
{
cout << "[" << i + 1 << "]: ";
cin >> tmp;
one.push_back(tmp);
}
}
void SearchAv(vector <int> & one)
{
int max = 0, min = 0;
float av;
for (int i = 0; i < one.size(); i++)
{
if (one[i] > max)
max = one[i];
if (one[i] < min)
min = one[i];
}
av = average(max, min);
cout << "Max: " << max << endl;
cout << "Min: " << min << endl;
cout << "Average: " << av;
}