Manh_LK

Star pyramid

Mar 22nd, 2020
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n;
  6.     cin >> n;
  7.     int length, left, right;
  8.     length = 4 * n - 3;
  9.     left = right = length / 2;
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         for (int j = 0; j < length; j++)
  13.         {
  14.             if (j >= left && j <= right)
  15.             {
  16.                 cout << "* ";
  17.                 j++;
  18.             }
  19.             cout << " ";
  20.         }
  21.         left -= 2;
  22.         right += 2;
  23.         cout << endl;
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment