Advertisement
vallec

1

Dec 15th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6. printf("Da se sustavi programa za obrabotka na dva masiva A[N,N] i B[N,N], kydeto dannite sa celi chisla v intervala [-1000;1000]. Programata da izvurshi slednite deistviq:\n");
  7. printf("Da se obrazuva ednomeren masiv C[N], elementite na koito da se obrazuvat kato suma ot suotvetnite elementi po glavnite diagonali na masivite A i B. Polucheniq masiv da se sortira po golemina.\n");
  8. printf("Avtor: ..........\n");
  9.  
  10. int n;
  11.  
  12. printf("Vavedi golemina na A i B: ");
  13. scanf("%d", &n);
  14. int A[n][n];
  15. int B[n][n];
  16.  
  17. for(int i = 0; i < n; i++){
  18. for(int j = 0; j < n; j++){
  19. printf("A[%d][%d] = ", i, j);
  20. scanf("%d", &A[i][j]);
  21. }
  22. }
  23.  
  24. for(int i = 0; i < n; i++){
  25. for(int j = 0; j < n; j++){
  26. printf("B[%d][%d] = ", i, j);
  27. scanf("%d", &B[i][j]);
  28. }
  29. }
  30.  
  31. printf("---------------\n");
  32.  
  33. for(int i = 0; i < n; i++){
  34. for(int j = 0; j < n; j++){
  35. printf("A[%d][%d] = %d\n", i, j, A[i][j]);
  36. }
  37. }
  38.  
  39. printf("---------------\n");
  40.  
  41. for(int i = 0; i < n; i++){
  42. for(int j = 0; j < n; j++){
  43. printf("B[%d][%d] = %d\n", i, j, B[i][j]);
  44. }
  45. }
  46.  
  47. int C[2];
  48. int sumA = 0;
  49. int sumB = 0;
  50.  
  51. for(int i = 0; i < n; i++){
  52. sumA += A[i][i];
  53. sumB += B[i][i];
  54. }
  55.  
  56. C[0] = sumA;
  57. C[1] = sumB;
  58.  
  59. int a;
  60.  
  61.  
  62. if (C[0] < C[1])
  63. {
  64. a = C[0];
  65. C[0] = C[1];
  66. C[1] = a;
  67. }
  68.  
  69. printf("Result:\n");
  70.  
  71. for (int i = 0; i < 2; i++)
  72. {
  73. printf("%d\n", C[i]);
  74. }
  75.  
  76.  
  77.  
  78. return 0;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement