Advertisement
rotti321

Valuri matrice

Mar 23rd, 2022
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 5 4 3 2 1
  3. 4 3 2 1 2
  4. 3 2 1 2 3
  5. 2 1 2 3 4
  6. 1 2 3 4 5
  7. */
  8.  
  9. //VAR I
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15. int n,a[100][100];
  16. cin>>n;
  17. for(int i=1;i<=n;i++){
  18. for(int j=1;j<=n;j++){
  19. a[i][j]=abs((n+1)-(i+j))+1;
  20. }
  21. cout<<endl;
  22. }
  23. for(int i=1;i<=n;i++){
  24. for(int j=1;j<=n;j++){
  25. cout<<a[i][j]<<" ";
  26. }
  27. cout<<endl;
  28. }
  29. return 0;
  30. }
  31.  
  32.  
  33.  
  34. //VAR II
  35. #include <iostream>
  36.  
  37. using namespace std;
  38.  
  39. int main() {
  40. int a[100][100],n;
  41. cin>>n;
  42. for(int i=1;i<=n;i++){
  43. for(int j=1;j<=n;j++){
  44. if(i+j==n+1){
  45. a[i][j]=1;
  46. }
  47. else {
  48. if(i+j<n+1){
  49. a[i][j]=n-i-j+1+1;
  50. a[n-i+1][n-j+1]=a[i][j];
  51. }
  52.  
  53. }
  54. }
  55. }
  56. for(int i=1;i<=n;i++){
  57. for(int j=1;j<=n;j++){
  58. cout<<a[i][j]<<" ";
  59. }
  60. cout<<endl;
  61. }
  62. return 0;
  63. }
  64.  
  65.  
Advertisement
RAW Paste Data Copied
Advertisement