You must Sign In to post a response.
  • Category: Programming

    Write a C program to add two 3 x 3 matrices


    Are you preparing for Diploma MSBTE exam? Looking out for a program solution for addition of two matrices? Our ISC experts shall provide you a program solution on this page to solve the problem.

    Following is a question that was asked in the question paper of Diploma in Electronics and Telecommunication Engineering (Summer 2019)conducted by MSBTE Mumbai, for subject C Programming (22218).

    This question is asked for 6 marks and hence requires some explanation along with the program code. Please let me know the solution.

    Q) Write a program to add two 3 × 3 matrices. [6 Marks]
  • Answers

    1 Answers found.
  • The thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Two dimensional array represents matrix structure. In two dimensional array first dimension represents row and second dimension represents column.
    e.g. int mat[2][3];
    In above example mat is name of array which holds all integer values. This array holds total 6 integers. In above declaration first dimension which is 2 which represents row and second dimension which is 3 that represents columns and hence this array has two rows and each row has three columns.
    In case of two or more dimensional array user have to use loop for accepting the array elements, processing array elements or outputting array elements. In general for every purpose user have to use loop.
    Below is the program to add two 3 x 3 matrices.
    Please include stdio.h and conio.h before main function.
    //ADDITION OF TWO MATRICES.
    #include
    #include
    void main(void)
    {
    int m1[3][3],m2[3][3],add[3][3],i,j;
    clrscr();
    printf("Enter first matrix elements(any 9 numbers)\n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&m1[i][j]);
    }
    }
    printf("Enter second matrix elements(any 9 numbers)\n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&m2[i][j]);
    }
    }
    printf("\n************************************************************\n");
    printf("Resultant matrix is as follows\n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    add[i][j]=m1[i][j]+m2[i][j];
    printf("%d ",add[i][j]);
    }
    printf("\n");
    }
    getch();
    }


  • Sign In to post your comments