Task-
Write a C Program to add two matrix using pointers.
1 3 6 2 4 8 3 7 14
2 4 5 + 3 6 7 = 5 10 12
3 5 8 6 7 5 9 12 13
For better understanding of pointers click here 👉👉 POINTERS
CODE:
#include<stdio.h>
void add(int x[2][2],int y[2][2]);
int main(){
int mat1[2][2]={{1,2},{3,4}},mat2[2][2]={{3,4},{5,6}};
add(mat1,mat2);
for (int i = 0;i<2;i++)
{
for (int j=0;j<2;j++)
{
printf("\t%d",mat1[i][j]);
}
printf("\n");
}
getchar();
return 0;
}
void add(int x[2][2],int y[2][2])
{
int mat3[2][2],*ad;
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
x[i][j]=x[i][j]+y[i][j];
}
}
}
Expected Output:
Sir, you make much easy c programing
ReplyDeleteGreat programming information.
ReplyDeleteThanx for sharing an excellent information
ReplyDelete