csansoon

P4.16 P66559 P0023. Els triangles bufons

Oct 24th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void buits(int n) {
  6.     if (n > 0) {
  7.         cout << " ";
  8.         buits(--n);
  9.     }
  10. }
  11.  
  12. void escriu_triangle(int t) {
  13.     for (int i = 1; i <= t*2; ++i) {
  14.         buits(t*2 - i);
  15.         if (i%2 != 0) {
  16.             for (int j = 1; j <= (i/2) + 1; ++j) {
  17.                 if (j != 1) cout << "  ";
  18.                 cout << "/\\";
  19.             }
  20.         }
  21.         else {
  22.             for (int j = 1; j <= i/2; ++j) {
  23.                 cout << "/__\\";
  24.             }
  25.         }
  26.         cout << endl;
  27.     }
  28.     cout << endl;
  29. }
  30.  
  31. int main() {
  32.     int x;
  33.     while (cin >> x && x > 0) {
  34.         escriu_triangle(x);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment