Advertisement
Josif_tepe

Untitled

Nov 23rd, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n;
  5.  
  6. void rec(int x) {
  7.     if(x == 1) {
  8.         for(int i = 0; i < n; i++) {
  9.             cout << "*";
  10.         }
  11.         cout << endl;
  12.         return;
  13.     }
  14.     if(x == n) {
  15.         for(int i = 0; i < n; i++) {
  16.             cout << "*";
  17.         }
  18.         cout << endl;
  19.     }
  20.     else {
  21.         for(int i = 0; i < n; i++) {
  22.             if(i == x - 1 or i == n - x) {
  23.                 cout << "*";
  24.             }
  25.             else {
  26.                 cout << " ";
  27.             }
  28.         }
  29.         cout << endl;
  30.     }
  31.     rec(x - 1);
  32. }
  33. int main(){
  34.     cin >> n;
  35.     rec(n);
  36.     return 0;
  37. }
  38. /*
  39.  n = 7
  40. 0 *******
  41. 1  *   *
  42. 2   * *
  43. 3    *
  44. 4   * *
  45. 5  *   *
  46. 6 *******
  47.  */
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement