-
Notifications
You must be signed in to change notification settings - Fork 14
/
14.cpp
53 lines (47 loc) · 898 Bytes
/
14.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
#include <iostream>
using namespace std;
int unos();
bool prost(int);
void program(int, int);
int main() {
int a = unos();
int b = unos();
program(a, b);
cin.get();
return 0;
}
int unos() {
int broj;
do {
cout << "Unesite broj : " << endl;
cin >> broj;
} while (broj < 1 || broj >= 500);
return broj;
}
bool prost(int broj) {
for (int i = 2; i <= broj / 2; i++)
{
if (broj % i == 0)
return false;
}
if (broj == 1)
return false;
return true;
}
void program(int a, int b) {
if (a > b) {
int temp = a;
a = b;
b = temp;
}
int najveciProstbr = 0;
for (int i = a + 1; i < b; i++)//a+1 da se izbjegne prva a i<b da se izbjegne zadnja, npr: 1 2 3 4 5 uzimace se cifre 2 3 4;
{
if (prost(i)) {
if (i > najveciProstbr) {
najveciProstbr = i;
}
}
}
cout << "Najveci prosti broj u datom intervalu zavrsava sa cifrom: " << najveciProstbr % 10 << endl;
}