C Program to Calculate Subtraction of Two Matrices (दो Matrices का घटाव ज्ञात करने का C प्रोग्राम)

Matrix subtraction is the process of subtracting the corresponding elements of one matrix from another matrix having the same number of rows and columns.

Matrix Subtraction वह प्रक्रिया है जिसमें समान 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], sub[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]);
}
}
/* Subtraction of two matrices */
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
sub[i][j] = a[i][j] - b[i][j];
}
}
printf("\nSubtraction of Matrix A and B is:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("%d\t", sub[i][j]);
}
printf("\n");
}
return 0;
}

Output (आउटपुट)

Enter elements of Matrix A:
Enter A[0][0] = 10
Enter A[0][1] = 20
Enter A[1][0] = 30
Enter A[1][1] = 40
Enter elements of Matrix B:
Enter B[0][0] = 1
Enter B[0][1] = 2
Enter B[1][0] = 3
Enter B[1][1] = 4
Subtraction of Matrix A and B is:
9 18
27 36

Explanation (व्याख्या)

The program uses two nested for loops to subtract the corresponding elements of Matrix B from Matrix A.

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

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

  • sub[R][C] stores the subtraction result.

  • sub[i][j] = a[i][j] - b[i][j]; subtracts corresponding elements.

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

इस प्रोग्राम में दो Nested for लूप का उपयोग किया गया है। प्रत्येक स्थान पर Matrix A के तत्व में से Matrix B का संगत तत्व घटाया जाता है और परिणाम को sub 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