Advertisement
Spocoman

Perfect Diamond

Oct 1st, 2023 (edited)
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. string repeat(string s, int n) {
  6.     string result;
  7.     for (int i = 0; i < n; i++) {
  8.         result += s;
  9.     }
  10.     return result;
  11. }
  12.  
  13. int main() {
  14.     int n;
  15.     cin >> n;
  16.    
  17.     for (int i = 0; i < n; i++) {
  18.         cout << repeat(" ", (n - (i + 1))) + '*' + repeat("-*", i) << endl;
  19.     }
  20.  
  21.     for (int i = n - 2; i >= 0; i--) {
  22.         cout << repeat(" ", (n - (i + 1))) + '*' + repeat("-*", i) << endl;
  23.     }
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement