Advertisement
mickypinata

SMMR-T044: Christmas Tree

Jun 3rd, 2021
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void printLoop(int n, char c){
  5.     for(int i = 1; i <= n; ++i){
  6.         printf("%c", c);
  7.     }
  8. }
  9.  
  10. int main(){
  11.  
  12.     int n;
  13.     scanf("%d", &n);
  14.  
  15.     // Top
  16.     printLoop(4 + n, ' ');
  17.     cout << "|\n";
  18.     printLoop(2 + n, ' ');
  19.     cout << "__*__\n";
  20.     printLoop(3 + n, ' ');
  21.     cout << "/|\\\n";
  22.     printLoop(2 + n, ' ');
  23.     cout << "/* *\\\n";
  24.  
  25.     // Leaves
  26.     int stBlank = n + 1;
  27.     int stNum = 2;
  28.     for(int l = 1; l <= n; ++l){
  29.         int blank = stBlank;
  30.         int num = stNum;
  31.         for(int i = 1; i <= 3; ++i){
  32.             printLoop(blank, ' ');
  33.             cout << "/*";
  34.             for(int j = 1; j <= num; ++j){
  35.                 cout << " *";
  36.             }
  37.             cout << "\\\n";
  38.             --blank;
  39.             ++num;
  40.         }
  41.         --stBlank;
  42.         ++stNum;
  43.     }
  44.  
  45.     // Stem
  46.     printLoop(3 + n, ' ');
  47.     cout << "|||\n";
  48.     printLoop(3 + n, '_');
  49.     cout << "|||";
  50.     printLoop(3 + n, '_');
  51.  
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement