fork download
  1. // saya menggunakan bahasa C++
  2. #include <iostream>
  3. #include <stdexcept>
  4. using namespace std;
  5.  
  6. void tekaTekiTeko(unsigned int batas) {
  7. if (batas < 20) {
  8. throw invalid_argument("Parameter harus bernilai minimal 20.");
  9. }
  10.  
  11. for (unsigned int i = 1; i <= batas; i++) {
  12. bool mod2 = (i % 2 == 0);
  13. bool mod3 = (i % 3 == 0);
  14. bool mod5 = (i % 5 == 0);
  15.  
  16. if (mod2 || mod3 || mod5) {
  17. if (mod2) cout << "Teka";
  18. if (mod3) cout << "Teki";
  19. if (mod5) cout << "Teko";
  20. cout << endl;
  21. } else {
  22. cout << i << endl;
  23. }
  24. }
  25. }
  26.  
  27. int main() {
  28. try {
  29. unsigned int batas;
  30. cout << "Masukkan angka batas (minimal 20): ";
  31. cin >> batas;
  32.  
  33. tekaTekiTeko(batas);
  34. } catch (const exception &e) {
  35. cerr << "Error: " << e.what() << endl;
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5316KB
stdin
30
stdout
Masukkan angka batas (minimal 20): 1
Teka
Teki
Teka
Teko
TekaTeki
7
Teka
Teki
TekaTeko
11
TekaTeki
13
Teka
TekiTeko
Teka
17
TekaTeki
19
TekaTeko
Teki
Teka
23
TekaTeki
Teko
Teka
Teki
Teka
29
TekaTekiTeko