C program to print product of 2 matrices (Program 23)

/*
Made by Anmol main
Student :B.tech CSE 
Punjabi university Patiala
Program No. : 23
*/
//number of rows of 1 matrix and number of colums of 2 matrix
#include <stdio.h>
#define n 3
int main()
{
    int ijk = 0;
    int sum = 0;
    int rowscolums;
    int browsbcolums;

    int product[n][n];
    int text[n][n];
    int text2[n][n];

    printf("Enter number of rows of matrix A: ");
    scanf("%d"&rows);
    printf("Enter number of colums of matrix A: ");
    scanf("%d"&colums);

    //getting input of 2 matrices
    for (i = 0i < rowsi++)
    {
        for (j = 0j < columsj++)
        {
            printf("A %d%d : "i + 1j + 1);
            scanf("%d"&text[i][j]);
        }
    }
    printf("\n\n");
    printf("Enter number of rows of matrix B: ");
    scanf("%d"&brows);
    printf("Enter number of colums of matrix B: ");
    scanf("%d"&bcolums);

    for (i = 0i < browsi++)
    {
        for (j = 0j < bcolumsj++)
        {
            printf("A %d%d : "i + 1j + 1);
            scanf("%d"&text2[i][j]);
        }
    }
    //printing 2 martrices
    printf("\nMatrix B :");
    for (i = 0i < rowsi++)
    {
        printf("\n");
        for (j = 0j < columsj++)
        {
            printf("%d "text[i][j]);
        }
    }
    printf("\n\nMatrix B :");
    for (i = 0i < browsi++)
    {
        printf("\n");
        for (j = 0j < bcolumsj++)
        {
            printf("%d "text2[i][j]);
        }
    }
    //resulatant matrix
    printf("\n\nResultant Matrix :");
    for (i = 0i < rowsi++)
    {
        for (j = 0j < bcolumsj++)
        {
            for (k = 0k < browsk++)
            {
                sum += text[i][k* text2[k][j];
            }
            product[i][j= sum;
            sum = 0;
        }
    }
    for (i = 0i < rowsi++)
    {
        printf("\n");
        for (j = 0j < bcolumsj++)
        {
            printf("%d    "product[i][j]);
        }
    }

    return 0;
}

Comments

Popular posts from this blog

Glowing-Log-in-window-in-Pure-html-css #30

Program to swap 2 numbers by using 3 numbers, taking input from user in C language. #1

C program to print lengh of an array (program 20)