-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathZadatak 03.cpp
61 lines (47 loc) · 1.04 KB
/
Zadatak 03.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
#include <iostream>
#include <cmath>
using namespace std;
void Ispis(int *niz, int velicina)
{
for (int i = 0; i < velicina; i++)
cout << niz[i] << endl;
}
void Popuni(int *niz, int velicina, int i = 0)
{
if (i < 0 || i >= velicina)
return;
int temp;
if(i == 0 || i == 1)
temp = 1;
else
temp = *(niz + i - 1) + *(niz + i - 2);
if (temp < 0) return;
*(niz + i) = temp;
Popuni(niz, velicina, i + 1);
}
int Postoji(int *niz, int vel, int broj, int i=0)
{
if (i >= vel)
return -1;
if (*(niz + i) == broj)
return i;
return Postoji(niz, vel, broj, i + 1);
}
int main()
{
int brojElemenata, broj;
while (cin >> brojElemenata, brojElemenata <= 0);
int *niz = new int[brojElemenata] {};
Popuni(niz, brojElemenata);
Ispis(niz, brojElemenata);
cout << "Koji broj u nizu trazite?";
cin >> broj;
int broj2 = Postoji(niz, brojElemenata, broj);
if (broj2 == -1)
cout << "Trazeni broj ne postoji u nizu." << endl;
else
cout << "Trazeni broj je na lokaciji: " << broj2 + 1 << endl;
delete[] niz;
system("pause>0");
return 0;
}