C Program to Calculate Addition of Two Matrices (दो Matrices का जोड़ ज्ञात करने का C प्रोग्राम)

Matrix addition is the process of adding the corresponding elements of two matrices having the same number of rows and columns.

Matrix Addition वह प्रक्रिया है जिसमें समान Rows और Columns वाली दो Matrices के संगत तत्वों को जोड़ा जाता है। इस प्रोग्राम में हम दो 2×2 Matrices का जोड़ ज्ञात करेंगे।

C Program

#include <stdio.h>
#define R 2
#define C 2
int main()
{
int a[R][C], b[R][C], add[R][C];
int i, j;
printf("Enter elements of Matrix A:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("Enter A[%d][%d] = ", i, j);
scanf("%d", &a[i][j]);
}
}
printf("\nEnter elements of Matrix B:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("Enter B[%d][%d] = ", i, j);
scanf("%d", &b[i][j]);
}
}
/* Addition of two matrices */
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
add[i][j] = a[i][j] + b[i][j];
}
}
printf("\nAddition of Matrix A and B is:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("%d\t", add[i][j]);
}
printf("\n");
}
return 0;
}

Output (आउटपुट)

Enter elements of Matrix A:
Enter A[0][0] = 1
Enter A[0][1] = 2
Enter A[1][0] = 3
Enter A[1][1] = 4
Enter elements of Matrix B:
Enter B[0][0] = 5
Enter B[0][1] = 6
Enter B[1][0] = 7
Enter B[1][1] = 8
Addition of Matrix A and B is:
6 8
10 12

Explanation (व्याख्या)

The program uses two nested for loops to read and add the corresponding elements of both matrices.

  • a[R][C] stores Matrix A.

  • b[R][C] stores Matrix B.

  • add[R][C] stores the result of addition.

  • add[i][j] = a[i][j] + b[i][j]; adds corresponding elements.

This program demonstrates matrix addition using a two-dimensional array in C.

प्रोग्राम में दो Nested for लूप का उपयोग किया गया है। पहला लूप Rows के लिए और दूसरा Columns के लिए चलता है। प्रत्येक स्थान पर Matrix A और Matrix B के तत्वों को जोड़कर परिणाम Matrix में संग्रहीत किया जाता है। यह प्रोग्राम C भाषा में 2D Array की सहायता से दो Matrices का जोड़ ज्ञात करना सिखाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025