Advertisement
monito2207

d1_1

Oct 31st, 2021 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. /**
  2. *
  3. * Solution to homework assignment 1
  4. * Introduction to programming course
  5. * Faculty of Mathematics and Informatics of Sofia University
  6. * Winter semester 2021/2022
  7. *
  8. * @author Monika Dobrinova
  9. * @idnumber 8MI0600008
  10. * @task 1
  11. * @compiler VC
  12. *
  13. */
  14.  
  15. #include <iostream>
  16. using namespace std;
  17. int main()
  18. {
  19.     int n;
  20.     cin >> n;
  21.  
  22.     if (n >= 1 && n <= 9)
  23.     {
  24.         for (int i = 1; i <= n; i++)
  25.         {
  26.             int k = 1;
  27.             while (k < i)
  28.             {
  29.                 cout << " ";
  30.                 k++;
  31.             }
  32.             for (int j = i; j <= n; j++)
  33.             {
  34.                 cout << j;
  35.             }
  36.             cout << endl;
  37.         }
  38.         int counter = n - 1;
  39.         for (int i = 1; i < n; i++)
  40.         {
  41.             for (int k = 1; k <= n - 1; k++)
  42.                 cout << " ";
  43.  
  44.             counter--;
  45.             for (int j = n; j > counter; j--)
  46.             {
  47.                 cout << j;
  48.             }
  49.             cout << endl;
  50.         }
  51.     }
  52.     else
  53.     {
  54.         cout << "-1";
  55.     }
  56.  
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement