fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Funkcja rysująca zbiór Cantora na danym poziomie
  5. void drawCantor(int x, int width, int level) {
  6. if (level == 0) {
  7. for (int i = 0; i < width; i++)
  8. cout << "-";
  9. cout << endl;
  10. return;
  11. }
  12.  
  13. int third = width / 3;
  14.  
  15. // Lewa część
  16. drawCantor(x, third, level - 1);
  17.  
  18. // Środkowa część (przerwa)
  19. for (int i = 0; i < third; i++)
  20. cout << " ";
  21. cout << endl;
  22.  
  23. // Prawa część
  24. drawCantor(x, third, level - 1);
  25. }
  26.  
  27. int main() {
  28. int level = 3;
  29. cout << "Podaj stopien zbioru Cantora (np. 3 lub 6): ";
  30. cin >> level;
  31.  
  32. if (level < 0) {
  33. cout << "Stopien musi byc >= 0!" << endl;
  34. return 1;
  35. }
  36.  
  37. int width = 1;
  38. for (int i = 0; i < level; i++)
  39. width *= 3;
  40.  
  41. drawCantor(0, width, level);
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Podaj stopien zbioru Cantora (np. 3 lub 6): -
 
-
   
-
 
-
         
-
 
-
   
-
 
-