fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // funkcja rysująca jedną linię
  5. void cantor(int level, int maxLevel) {
  6. if (level == 0) {
  7. cout << "#";
  8. } else {
  9. cantor(level - 1, maxLevel);
  10.  
  11. // środkowa przerwa
  12. int spaces = 1;
  13. for (int i = 0; i < level - 1; i++) {
  14. spaces *= 3;
  15. }
  16. for (int i = 0; i < spaces; i++) {
  17. cout << " ";
  18. }
  19.  
  20. cantor(level - 1, maxLevel);
  21. }
  22. }
  23.  
  24. int main() {
  25. int stopien;
  26. cout << "Podaj stopien (np. 3 lub 6): 3 ";
  27. cin >> stopien;
  28.  
  29. if (stopien < 0 || stopien > 6) {
  30. cout << "Podaj stopien 0–6!" << endl;
  31. return 0;
  32. }
  33.  
  34. // rysujemy kolejne poziomy
  35. for (int i = 0; i <= stopien; i++) {
  36. cantor(i, stopien);
  37. cout << endl;
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Podaj stopien (np. 3 lub 6): 3 Podaj stopien 0–6!