Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- 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");
- 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");
- printf("Avtor: ..........\n");
- int n;
- printf("Vavedi golemina na A i B: ");
- scanf("%d", &n);
- int A[n][n];
- int B[n][n];
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("A[%d][%d] = ", i, j);
- scanf("%d", &A[i][j]);
- }
- }
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("B[%d][%d] = ", i, j);
- scanf("%d", &B[i][j]);
- }
- }
- printf("---------------\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("A[%d][%d] = %d\n", i, j, A[i][j]);
- }
- }
- printf("---------------\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("B[%d][%d] = %d\n", i, j, B[i][j]);
- }
- }
- int C[2];
- int sumA = 0;
- int sumB = 0;
- for(int i = 0; i < n; i++){
- sumA += A[i][i];
- sumB += B[i][i];
- }
- C[0] = sumA;
- C[1] = sumB;
- int a;
- if (C[0] < C[1])
- {
- a = C[0];
- C[0] = C[1];
- C[1] = a;
- }
- printf("Result:\n");
- for (int i = 0; i < 2; i++)
- {
- printf("%d\n", C[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement