Advertisement
Madjohnny

Vejailla problem,Took me 1 hour to finish

Mar 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int m,n;
  7.     printf("Number of rows(first matrix):?\n");
  8.     scanf("%d",&m);
  9.     printf("Number of columns?(first matrix):\n");
  10.     scanf("%d",&n);
  11.  
  12.     printf("Enter The value of Matrix(first matrix):\n");
  13.  
  14. int i,j,ar[m][n];
  15.  
  16.     for(i=1;i<=m;i++)
  17.     {
  18.  
  19.         for(j=1;j<=n;j++)
  20.             {
  21.                 printf("Enter the %d Row and %d Column:",i,j);
  22.                 scanf("%d",&ar[i][j]);
  23.             }
  24.     }
  25.     printf("Given Matrix:\n");
  26.  
  27.     for(i=1;i<=m;i++)
  28.         {
  29.             for(j=1;j<=n;j++)
  30.             {
  31.                 printf("%d\t",ar[i][j]);
  32.             }
  33.             printf("\n");
  34.         }
  35.         int q,w;
  36.     printf("Number of rows?(Second matrix):\n");
  37.     scanf("%d",&q);
  38.     printf("Number of columns?(Second matrix):\n");
  39.     scanf("%d",&w);
  40.  
  41.     printf("Enter The value of Matrix(Second matrix):\n");
  42.  
  43. int ar1[q][w];
  44.  
  45.     for(i=1;i<=q;i++)
  46.     {
  47.  
  48.         for(j=1;j<=w;j++)
  49.             {
  50.                 printf("Enter the %d Row and %d Column:",i,j);
  51.                 scanf("%d",&ar1[i][j]);
  52.             }
  53.     }
  54.     printf("Given Matrix(Second matrix):\n");
  55.  
  56.     for(i=1;i<=q;i++)
  57.         {
  58.             for(j=1;j<=w;j++)
  59.             {
  60.                 printf("%d\t",ar1[i][j]);
  61.             }
  62.             printf("\n");
  63.         }
  64.         printf("\n");
  65.        printf("Sum of the two matrixes:\n");
  66.         int add[q][w];
  67.         if(m==q && n==w)
  68.         {
  69.  
  70.  
  71.              for(i=1;i<=q;i++)
  72.         {
  73.             for(j=1;j<=w;j++)
  74.             {
  75.             add[i][j]=ar[i][j]+ar1[i][j];
  76.             }
  77.             printf("\n");
  78.         }
  79.  
  80.             for(i=1;i<=q;i++)
  81.         {
  82.             for(j=1;j<=w;j++)
  83.             {
  84.  
  85.                 printf("%d\t",add[i][j]);
  86.             }
  87.             printf("\n");
  88.         }
  89.         }
  90.         else
  91.         {
  92.                 printf("Error");
  93.         }
  94.  
  95.  return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement