C program to add subtract matrices by using pointer.
Subtraction of two matrices by using pointer in c programming.
Subtract two matrices using pointer in C.
In this tutorial we will learn or discuss that how to write a c program code to subtract two matrix by using c language. In this program we will use arrays.
This c program code will sub two matrices.
In the first user will enter range of rows and columns. After it user enter the elements of first matrix then second matrix.
After it compiler check and exicute the condition and logics and print a new matrix in which both matrixes are subtracted.
C PROGRAM CODE
#include<stdio.h>
main()
{
int i,j,rows,col;
int a1[100][100],a2[100][100],sub[100][100];
printf("\n ENTER NUMBER OF ROWS:\n ");
scanf("%d",&rows);
printf("\n ENTER NUMBER OF COLUMNS:\n ");
scanf("%d",&col);
//Taking input for 1st matrix
printf("\n ENTER FIRST MATRIX:\n ");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",(*(a1+i)+j));
}
}
//Taking input for 2nd matrix
printf("\n ENTER SECOND MATRIX:\n ");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",(*(a2+i)+j));
}
}
//Subtraction of matrix
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
*(*(sub+i)+j)=*(*(a1+i)+j)-*(*(a2+i)+j);
}
}
printf("\n SUBTRACTION OF ABOVE MATRICES:\n ");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",*(*(sub+i)+j));
}
printf("\n ");
}
}
OUTPUT:
Ssubtraction of two matrices |
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment