bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / APC-S-008.c

APC-S-008.c (1437B)


      1 /* Write a program to print the sum of two matrix as input given by the user. */
      2 /* Author: Amit Dutta, Date: 18-11-2025 */
      3 
      4 #include <stdio.h>
      5 
      6 int main()
      7 {
      8     int rows, cols, i, j;
      9     printf("Enter the number of rows and columns: ");
     10     scanf("%d %d", &rows, &cols);
     11 
     12     int a[rows][cols], b[rows][cols], c[rows][cols];
     13 
     14     printf("Enter the elements of matrix A (%d x %d): \n", rows, cols);
     15     for (i = 0; i < rows; i++)
     16         for (j = 0; j < cols; j++)
     17         {
     18             printf("Position %d%d: ", i, j);
     19             scanf("%d", &a[i][j]);
     20         }
     21     printf("\nMatrix A: \n");
     22     for (i = 0; i < rows; i++)
     23     {
     24         for (j = 0; j < cols; j++)
     25             printf("%d  ", a[i][j]);
     26         printf("\n");
     27     }
     28 
     29     printf("\nEnter the elements of matrix B(%d x %d): \n", rows, cols);
     30     for (i = 0; i < rows; i++)
     31         for (j = 0; j < cols; j++)
     32         {
     33             printf("Position %d%d: ", i, j);
     34             scanf("%d", &b[i][j]);
     35         }
     36     printf("\nMatrix B: \n");
     37     for (i = 0; i < rows; i++)
     38     {
     39         for (j = 0; j < cols; j++)
     40             printf("%d  ", b[i][j]);
     41         printf("\n");
     42     }
     43 
     44     for (i = 0; i < rows; i++)
     45         for (j = 0; j < cols; j++)
     46             c[i][j] = a[i][j] + b[i][j];
     47 
     48     printf("\nResult Matrix: \n");
     49     for (i = 0; i < rows; i++)
     50     {
     51         for (j = 0; j < cols; j++)
     52             printf("%d  ", c[i][j]);
     53         printf("\n");
     54     }
     55 
     56     return 0;
     57 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror