Write a C Program to add two matrix using pointers and functions

 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:



NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

3 Comments

Post a Comment
Previous Post Next Post