adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Write a program in C to add two matrix.

Write a program in C to add two matrix.

1:  #include<stdio.h>  
2:  #include<conio.h>  
3:   void main()  
4:    {  
5:    int m1[100][100],m2[100][100],m3[100][100];  
6:    int i,j,m,n;  
7:    clrscr();  
8:    printf("Enter no. of rows:-");  
9:    scanf("%d",&m);  
10:    printf("Enter no. of columns:-");  
11:    scanf("%d",&n);  
12:    printf("Enter first matrix size %d*%d :-\n",m,n);  
13:    for(i=0;i<m;i++)  
14:    {  
15:     for(j=0;j<n;j++)  
16:      scanf("%d",&m1[i][j]);  
17:     }  
18:     printf("Enter second matrix size %d*%d :-\n",m,n);  
19:     for(i=0;i<m;i++)  
20:     {  
21:     for(j=0;j<n;j++)  
22:      scanf("%d",&m2[i][j]);  
23:      }  
24:      for(i=0;i<m;i++)  
25:       {  
26:        for(j=0;j<n;j++)  
27:        m3[i][j]=m1[i][j]+m2[i][j];  
28:        }  
29:       printf("Addition of matix \n");  
30:       for(i=0;i<m;i++)  
31:        {  
32:        for(j=0;j<n;j++)  
33:        printf("%4d",m3[i][j]);  
34:        printf("\n");  
35:        }  
36:        getch();  
37:        }  

Output:


Post a Comment

0 Comments