Advertisement
Spocoman

04. Printing Triangle

Oct 26th, 2023
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void printTiangle(int n) {
  7.     string result = "";
  8.  
  9.     for (int i = 1; i <= n; i++) {
  10.         for (int j = 1; j <= i; j++) {
  11.             result += to_string(j) + " ";
  12.         }
  13.         result += "\n";
  14.     }
  15.     for (int i = n; i > 0; i--) {
  16.         for (int j = 1; j < i; j++) {
  17.             result += to_string(j) + " ";
  18.         }
  19.         result += "\n";
  20.     }
  21.     cout << result;
  22. }
  23.  
  24. int main() {
  25.     int n;
  26.     cin >> n;
  27.  
  28.     printTiangle(n);
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement