Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- int sum_diagonal(int **a, int N) {
- int s, i, j;
- s = 0;
- for (i=0; i< N; i++)
- s += a[i][i];
- return s;
- }
- void Input(int **a, int N){
- for (int i=0; i< N; i++) {
- for (int j=0; j< N; j++) {
- a[i][j] = rand() % 10;
- }
- }
- }
- void Ouput(int **a, int N){
- for (int i=0; i< N; i++) {
- for (int j=0; j< N; j++) {
- printf("%3d", a[i][j]);
- }
- printf("\n");
- }
- }
- int main()
- {
- int N = 3;
- int ** A = (int**) malloc (sizeof (int*) * N);
- for (int i = 0; i < N; i++) {
- A[i] = (int*) malloc (sizeof (int)*N);
- }
- Input(A, N);
- printf("Matrix A:\n");
- Ouput(A, N);
- int M = 4;
- int ** B = (int**) malloc (sizeof (int*) * M);
- for (int i = 0; i < M; i++) {
- B[i] = (int*) malloc (sizeof (int)*M);
- }
- Input(B, M);
- printf("Matrix B:\n");
- Ouput(B, M);
- printf("\nСума елементів діагоналей матриці А і В = %d", sum_diagonal(A, N) + sum_diagonal(B, M));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment