| 01 | #include <iostream.h> | 
| 02 | #include <conio.h> | 
| 03 | 
| 04 | classBagi{ | 
| 05 |  friendistream& operator>>(istream&, Bagi &); | 
| 06 |  friendostream& operator<<(ostream&, Bagi&); | 
| 07 |  public: | 
| 08 |  Bagi(); | 
| 09 |  voidproses(); | 
| 10 |  intbagi(inta); | 
| 11 |  private: | 
| 12 |  inta; | 
| 13 |  }; | 
| 14 | 
| 15 | Bagi::Bagi(){ | 
| 16 | cout<<"Mencetak bilangan yang habis dibagi 5 dan 7 antara 1 sampai 100"<<endl; | 
| 17 |  } | 
| 18 | //iteratif | 
| 19 | voidBagi::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 | intBagi::bagi (inta){ | 
| 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 | intmain(){ | 
| 41 | 
| 42 |  Bagi X; | 
| 43 |  X.proses(); | 
| 44 |  X.bagi(1); | 
| 45 | 
| 46 | getch(); | 
| 47 | } | 
| 48 | <pre> | 
 
Tidak ada komentar:
Posting Komentar