SET OF PROGRAMS

This blog provided "C" programs for beginners. Providing c programs for students.enjoy this blog.this blog include many c programs for engineering students, IT engineering students and programmers this blog is very useful.this blog post daily 1-5 programs for you.this programs use full for devlop games devlops application and much more. This blog programs useful for projects because all programs post with explanations.

Search Bar

Ads Here

Saturday, 22 September 2018

C program for add two matrices

C Program for Add 2 Matrices
#include<stdio.h>
main()
{
 int i,j,rows,col;
 printf("Enter number of rows\n");
 scanf("%d",&rows);
  printf("Enter number of columns\n");
 scanf("%d",&col);

 int a1[rows][col],a2[rows][col],add[rows][col];
 //Taking input for 1st matrix
 printf("Enter Matrix 1\n");
 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   scanf("%d",&a1[i][j]);
  }
 }
  //Taking input for 2nd matrix
  printf("Enter Matrix 2\n");
 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   scanf("%d",&a2[i][j]);
  }
 }
 //Addition of matrix
 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   add[i][j]=a1[i][j]+a2[i][j];
  }
 }

 printf("Addition of above matrices is\n");

  for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   printf("%d\t",add[i][j]);
  }

  printf("\n");
 }

}
Output:
Enter number of rows
2
Enter number of columns
2
Enter Matrix 1
30
35
12
34
Enter Matrix 2
1
2
3
4

Addition of above matrices is
31      37
15      38

Explanation:
//Coming Soon..

No comments:

Post a Comment