Write a C Program to Print the Multiplication of Two Matrices

    Multiplication of Matrix
    Statement of C Program: This Program accepts two Matrices of different or same order and Find the product of these Matrices and prints the Product Matrix:

    Condition: The Column of First Matrix must be Equal to the Row of the Second Matrix.




    Matrix Multiplication Condition

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int Matrix A[9][9] , MatrixB[9][9] , Matrixsproduct [9][9] ;

    int n , i , j , k;                              /* 'i' used for rows and 'j' used for columns */

    int Row1 , Row2 , Column1 , Column2;
    clrscr();
    printf(" Enter the order of Matrix A\n");
    scanf("%d * %d " , &Row1 , &Column1);

    printf(" Enter the order of Matrix B\n");
    scanf("%d * %d " , &Row2 , &Column2);

    if(Column1 == Row2)
    {
    printf(" Enter the elements of Matrix A\n");
    for(i=0 ; i<Row1 ; i++)
    {
    for(j=0 ; j<Column1 ; j++)
    {
    scanf("%d" , &Matrix A[i][j] );
    }
    }

    printf(" Enter the elements of Matrix B\n");
    for(i=0 ; i<Row2 ; i++)
    {
    for(j=0 ; j<Column2 ; j++)
    {
    scanf("%d" , &Matrix B[i][j] );
    }
    }

                                                         /* Product of two Matrices */

    for(i=0 ; i<Row1 ; i++)
    {
    for(j=0 ; j<Column2 ; j++)
    {
    Matrixproduct[i][j] = 0 ;
    for(k=0 ; k<Row2 ; k++)
    {
    Matrixproduct[i][j] = Matrixproduct[i][j] + ( Matrix A[i][k] * Matrix B[k][j] );
    }
    }
    }

    printf(" Product Matrix\n");
    for(i=0 ; i< Row1 ; i++)
    {
    for(j=0 ;j< Column2;j++)
    {
    printf("%d" , Matrixproduct[i][j] );
    }
    printf("\n");
    }
    }                                                                    /* End of if */

    else
    {
    printf(" Invalid order so Multiplication not possible\n");
    }                                                                 /* End of main() */

     Output:
     Enter the order of Matrix A
     2 * 2
     Enter the order of MatrixB
     2 * 2
     Enter the elements of Matrix A
     1
     2
     3
     4
     Enter the elements of Matrix B 
     5
     6
     7
     8
     Product Matrix
     19      22
     43      50


                                                                  That's All

    0 Response to "Write a C Program to Print the Multiplication of Two Matrices"

    Post a Comment

    Popular Posts

    Label

    1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag