0% found this document useful (0 votes)
3 views

sum 2D

The document contains a C program that prompts the user to input the size of two square matrices, A and B. It then allows the user to input the elements of both matrices, prints them, and calculates their sum. Finally, the program displays the resulting matrix from the addition of A and B.

Uploaded by

raj.redmi4556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

sum 2D

The document contains a C program that prompts the user to input the size of two square matrices, A and B. It then allows the user to input the elements of both matrices, prints them, and calculates their sum. Finally, the program displays the resulting matrix from the addition of A and B.

Uploaded by

raj.redmi4556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Online C compiler to run C program online

#include <stdio.h>

int main() {
// Write C code here
int n;
printf("Enter array size: ");
scanf("%d",&n);
int A[n][n],B[n][n];

//input data in array


printf("\nMatrix A:\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]);
}
}
printf("\nMatrix B:\n");
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");
//print matrix A
printf("\nMatrix A:\n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",A[i][j]);
}
printf("\n");
}

printf("\n");
//print matrix B
printf("\nMatrix B:\n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",B[i][j]);
}
printf("\n");
}

printf("\n");
//print sum A+B
printf("\nMatrix A+B:\n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",A[i][j]+B[i][j]);
}
printf("\n");
}

printf("SS value ");


return 0;
}

You might also like