-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_ex_6.cpp
executable file
·67 lines (58 loc) · 1.11 KB
/
vector_ex_6.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <math.h>
#include <vector>
#include <stdlib.h>
using namespace std;
void printVector (vector<int> V)
{
int i, len = V.size();
for (i = 0; i<len; i++)
{
cout << V[i] << "|";
}
cout << endl;
}
vector<int> caricaVettore()
{
int lunghezza;
cout << "Inserire lunghezza vettore = ";
cin >> lunghezza;
vector<int> V (lunghezza, 0);
int i;
for (i=0; i<=lunghezza-1; i++)
{
cout << "Inserire numero = ";
cin >> V[i];
}
return V;
}
void cercaValori(vector<int> V)
{
int min = 0;
int max = 0;
int len = V.size();
for (int i = 0; i<len; i++)
{
if (i == 0)
{
min = V[i];
max = V[i];
}
else
{
if (min > V[i])
min = V[i];
if (max < V[i])
max = V[i];
}
}
cout << "VALORE MINIMO :"<< min << endl;
cout << "VALORE MASSIMO :"<< max << endl;
}
int main()
{
vector<int> vettore = caricaVettore();
printVector(vettore);
cercaValori(vettore);
system("pause");
}