C program to subtract Matrix1 to Mtrix2.

Question:

Write a C program to take elements of two matrix 3 X 3 and do the subtraction and display the result.

Source Code:

#include<stdio.h> int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&mat1[i][j]); } } printf("Enter elements of Matrix 2\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&mat2[i][j]); } } printf("elements of Matrix 1\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d \t",mat1[i][j]); } printf("\n"); } printf("elements of Matrix 2\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d \t",mat2[i][j]); } printf("\n"); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { mat3[i][j]=mat1[i][j]-mat2[i][j]; } } printf("Subtraction of two matrix is:\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d \t",mat3[i][j]); } printf("\n"); } return 0; }

Output:

Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Subtraction of two matrix is: 0 0 0 0 0 0 0 0 0

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.