01 | #include <iostream.h> |
02 | #include <conio.h> |
03 |
04 | class Bagi{ |
05 | friend istream& operator>>(istream&, Bagi &); |
06 | friend ostream& operator<<(ostream&, Bagi&); |
07 | public : |
08 | Bagi(); |
09 | void proses(); |
10 | int bagi( int a); |
11 | private : |
12 | int a; |
13 | }; |
14 |
15 | Bagi::Bagi(){ |
16 | cout<< "Mencetak bilangan yang habis dibagi 5 dan 7 antara 1 sampai 100" <<endl; |
17 | } |
18 | //iteratif |
19 | void Bagi::proses(){ |
20 | a =1; |
21 | while (!(a>100)){ |
22 | if (a % 5==0 && a % 7==0){ |
23 | cout << a << endl; |
24 | } else {} |
25 | a =a+1; |
26 | } |
27 | } |
28 | //rekursif |
29 | int Bagi::bagi ( int a){ |
30 | if (a>100){ |
31 | } else |
32 | { |
33 | if (a % 5==0 && a % 7==0) |
34 | { |
35 | cout << a << endl; } |
36 | else |
37 | {}bagi(a+1); |
38 | }} |
39 |
40 | int main(){ |
41 |
42 | Bagi X; |
43 | X.proses(); |
44 | X.bagi(1); |
45 |
46 | getch(); |
47 | } |
48 | <pre> |
Tidak ada komentar:
Posting Komentar