-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegundo_menor.cpp
More file actions
39 lines (36 loc) · 767 Bytes
/
Copy pathsegundo_menor.cpp
File metadata and controls
39 lines (36 loc) · 767 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
// Funçao segundo menor
#include <iostream>
#define MAX 100
using namespace std;
// declarando funcao leitura
void leitura(int v[])
{
int i = 0;
do
{
cin >> v[i];
i++;
} while (v[i - 1] != -1);
}
int segundomenor(int v[])
{
//teste menor
int i = 0, menor = v[0], menor2 = v[0];
while (v[i] != -1) // instruçao de parada com while
{
if (v[i] < menor)
menor = v[i];
i++;
}
return menor;
//segundo menor
}
// funcao principal
int main()
{
int vetor[MAX]; // chamando o vetor
leitura(vetor); // chamando funcao leitura
segundomenor(vetor); // chamando teste segundo menor
cout << "segundo menor: " << segundomenor(vetor); // impressao na tela
return 0;
}