JosepRivaille

P66559: Els triangles bufons

Apr 5th, 2015
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 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 << "/" << char(92);
  19.                 //Desconec la forma d'implementar '\' en C++ per tant accedeixo a la taula
  20.                 //ASCII amb la comanda 'man ascii' i introdueixo directament el caràcter corresponent
  21.             }
  22.         }
  23.         else {
  24.             for (int j = 1; j <= i/2; ++j) {
  25.                 cout << "/__" << char(92);
  26.             }
  27.         }
  28.         cout << endl;
  29.     }
  30.     cout << endl;
  31. }
  32.  
  33.  
  34. //Pre: Llegeix una seqüència de naturals
  35. //Post: Escriu triangles bufons de mida x
  36. int main() {
  37.     int x;
  38.     while (cin >> x && x > 0) {
  39.         escriu_triangle(x);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment