Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:59:34+00:00 2026-05-25T22:59:34+00:00

Trying to make 3 x 3 matrix multiplier but it gives out wrong output.

  • 0

Trying to make 3 x 3 matrix multiplier but it gives out wrong output. I don’t know what I am doing wrong. Two problems that I am facing are:

(1) Some variables store wrong input. For example a[1][1] shows 7 although I entered 1

(2) The matrix multiplication is wrong

#include <stdio.h>
#include <conio.h>

void matrix_format(int m[2][2])
{
 int i,j;
 printf("\n\n");
 for(i=0;i<=2;i++)
 {
  for(j=0;j<=2;j++)
   {
    if(j==0)
    printf("[ %d |",m[i][j]);
    else if(j==1)
    printf(" %d |",m[i][j]);
    else if(j==2)
    printf(" %d ] \n",m[i][j]);
   }
 }
}


int main(void)
{
 void matrix_format(int [2][2]);
 int a[2][2], b[2][2], r[2][2],m,i,j;

 clrscr();

 for(m=1;m<=2;m++)
 {

  if(m==1)
   {
    printf("Enter values for the matrix A \n");
   }
  else
   {
    printf("\n\nEnter values for the matrix B \n");
   }

  for(i=0;i<=2;i++)
  {
   for(j=0;j<=2;j++)
    {
     if(m==1)
      {
       printf("A[%d][%d] : ",i+1,j+1);
       scanf("%d",&a[i][j]);
      }
     else if(m==2)
      {
       printf("B[%d][%d] : ",i+1,j+1);
       scanf("%d",&b[i][j]);
      }
    }
  }
 }

 printf("\n Matrix A : \n");
 matrix_format(a);

 printf("\n Matrix B : \n");
 matrix_format(b);

 for(i=0;i<=2;i++)
 {
  for(j=0;j<=2;j++)
   {
    r[i][j]= a[i][j] * b[j][i];
   }
 }

 printf("\n Matrix Multiplication Result : \n");
 matrix_format(r);

 getch();
 return 0;
}

output:

enter image description here
enter image description here

Please guide me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:59:35+00:00Added an answer on May 25, 2026 at 10:59 pm

    The first problem that jumps out is that all your arrays are 2×2, while they should be 3×3:

    m[2][2]
    

    should read

    m[3][3]
    

    and so on. The number in brackets is the size of the array, not the index of the last element.

    This will explain some of the weirdness, in particular why some elements get mysteriously overwritten.

    As to the actual matrix multiplication, your algorithm isn’t quite right (assuming what you’re trying to implement is the standard linear algebra matrix product). Think about what steps are involved in multiplying two matrices, and what your code is actually doing. Since this is homework, I’ll only give you a hint:

    Matrix product involves summations of element products.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a struct that generates a random matrix and am getting
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
Im trying to make a function that will return an element of type point:
I am trying to write a simple matrixMultiplication application that multiplies two square matrices
I'm trying to make an application with flash builder that performs operations on square
So I'm trying to make a little Matrix themed program, I want the user
I am trying to make an algorithm for the following task: I have two
I am trying to make one figure by stacking two graphs (a) and (b)
I'm trying to make a wrapper for some C-based sparse-matrix-handling code (see previous question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.