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 7596319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:53:27+00:00 2026-05-30T21:53:27+00:00

I set up my code without considering this fact needed to be detected, and

  • 0

I set up my code without considering this fact needed to be detected, and as a result I can’t seem to figure out how to implement it now. This is a simple matrix multiplier.

Basically, it needs to detect two conditions.

  1. If the columns in matrix 1 is not equal to the rows in matrix 2, exit the program with an error message. I have done this.

  2. If the value the user inputs for the row and column values for matrix1 and matrix2 are non-zero, positive values. I’m having trouble with this.

The way our prof has it set up is that we copy and paste in a set of values and it does it. But if we’re copy and pasting it in to the input, I’m confused how it should detect the error with rows and columns when in order to accept the rest of the data I’m using for loops to scan all the values in, and the length of the for loop is dependent on the input of rows and columns for matrix1 and matrix2. If those are negative, the for loop won’t work anyway.

Really, any help would be appreciated, I’ve got every other part finished except this minute detail. Thanks so much.

#include <stdio.h>

int main(int argc, char *argv[]) {
    int rows1 = 1, columns1 = 1, rows2 = 1, columns2 = 1;    // variables for number of rows and columns in each matrix 
    int i, j, k;                                             // loop variables 

    // These will affect the loop's length
    scanf("%d %d", &rows1, &columns1);
    int matrix1[rows1][columns1];
    for (i = 0; i < rows1; i++) {
        for (j = 0; j < columns1; j++) {
            scanf("%d", &matrix1[i][j]);
        }
    }

    scanf("%d %d", &rows2, &columns2);
    int matrix2[rows2][columns2];
    for (i = 0; i < rows2; i++) {
        for (j = 0; j < columns2; j++) {
            scanf("%d", &matrix2[i][j]);
        }
    }

    int resultMatrix[rows1][columns2]; // Initialization of resultMatrix, that holds the result of the multiplication

    int matrix1RowIndex = 0, matrix1ColIndex = 0, matrix2ColIndex = 0;

    if (columns1 != rows2) {
        printf("Sorry, the amount of columns in the first matrix must equal the amount of rows in the second matrix.\n");
    }
    else {      
        // Loop to set the values of resultMatrix's indices
        for (i = 0; i < rows1; i++) { // rows
            for (j = 0; j < columns2; j++) { // columns
                resultMatrix[i][j] = 0;
                for (k = 0; k < columns1; k++) { // for each individual index to be summed for the resultMatrix's value
                    resultMatrix[i][j] += (matrix1[matrix1RowIndex][matrix1ColIndex + k] * matrix2[matrix1ColIndex + k][matrix2ColIndex]);
                }
                matrix2ColIndex++;
            }
            matrix1RowIndex++;
            matrix2ColIndex = 0;
        }

        //prints resultMatrix
        for (i = 0; i < rows1; i++) { // rows
            for (j = 0; j < columns2; j++) { // columns
                printf("%6d", resultMatrix[i][j]);
            }
            printf("\n");
        }
    }
}
  • 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-30T21:53:28+00:00Added an answer on May 30, 2026 at 9:53 pm

    It would seem that you can just check that the values in question are greater than zero using an if statement, can’t you?

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

Sidebar

Related Questions

How can I define this animation xml by java code without using xml <set
How can I set the printing size (width and height) by code without showing
How do I set IncludeExceptionDetailInFaults in code without using App.Config?
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
Initially I ran this code without the leading cmd and I received an access
Is it possible to set code behind a resource dictionary in WPF. For example
How do I set the code page to UTF-8 in a C Windows program?
How does the Chinese GB18030 code set differ from Unicode? What special techniques are
I currently have my code set to disable the submit button when the field
I have the following code set up in my Startup IDictionary<string, string> properties =

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.