bsc

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

root / semester_1 / letusc / luc067.c

luc067.c (1228B)


      1 /* Write a program to multiply any two 3 x 3 matrices.
      2 */
      3 
      4 /* Let Us C, Chap- 14 (Multidimensional Arrays), Qn No.: C(g) */
      5 
      6 /* This file is auto-generated by a bot. */
      7 /* This code is not compiled; it is for reference only. */
      8 
      9 
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 
     13 int main()
     14 {
     15     int mat1[3][3], mat2[3][3], res[3][3];
     16     int i, j, k;
     17 
     18     printf("Enter elements of first 3x3 matrix:\n");
     19     for (i = 0; i < 3; i++)
     20         for (j = 0; j < 3; j++)
     21             scanf("%d", &mat1[i][j]);
     22 
     23     printf("Enter elements of second 3x3 matrix:\n");
     24     for (i = 0; i < 3; i++)
     25         for (j = 0; j < 3; j++)
     26             scanf("%d", &mat2[i][j]);
     27 
     28     // Initialize result matrix to 0
     29     for (i = 0; i < 3; i++)
     30         for (j = 0; j < 3; j++)
     31             res[i][j] = 0;
     32 
     33     // Multiplication Logic
     34     for (i = 0; i < 3; i++)
     35     {
     36         for (j = 0; j < 3; j++)
     37         {
     38             for (k = 0; k < 3; k++)
     39             {
     40                 res[i][j] += mat1[i][k] * mat2[k][j];
     41             }
     42         }
     43     }
     44 
     45     printf("\nResult of Multiplication:\n");
     46     for (i = 0; i < 3; i++)
     47     {
     48         for (j = 0; j < 3; j++)
     49         {
     50             printf("%4d ", res[i][j]);
     51         }
     52         printf("\n");
     53     }
     54 
     55     return 0;
     56 }
© 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