Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. do
  8. {
  9. cin >>n;
  10. if (n<1 || n>100) cout <<"1<=n<=100\n";
  11. }
  12. while (n<1 || n>100);
  13.  
  14. int **a = new int*[n];
  15. for (int i = 0; i < n; i++)
  16. a[i]=new int[n];
  17.  
  18. for (int i = 0; i < n; i++)
  19. {
  20. for (int j = 0; j < n; j++)
  21. {
  22. if (i<n-1-j) a[i][j]=0;
  23. else if (i>n-1-j) a[i][j]=2;
  24. else a[i][j]=1;
  25. cout <<a[i][j]<<" ";
  26. }
  27. cout <<endl;
  28. }
  29. for (int i = 0; i < n; i++)
  30. delete [] a[i];
  31. delete [] a;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement