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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:43:18+00:00 2026-05-30T15:43:18+00:00

The the code for that portion, if you want to compile it is below.

  • 0

The the code for that portion, if you want to compile it is below.

Basically I have to take the following data and input it into the program:

4 5
12 5 7 0 -3
9 11 2 5 4
0 -5 9 6 1
2 12 93 -15 0
5 3
7 1 31
0 0 5
-5 -3 2
9 41 11
0 13 31

The first 4 5 & 5 3 represent the dimensions of the first and second matrix, while the data after it is the data for the matrix.

The problem is, when I copy and paste that in, it asks for one more input afterward, and when I input anything (say 84) it works flawlessly (output wise), and the 84 appears to do nothing. Why’s it asking for this extra one?

#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]);
            }
        }
}
  • 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-30T15:43:19+00:00Added an answer on May 30, 2026 at 3:43 pm

    The behaviour is due to the spaces in:

    scanf("%d ", &matrix1[i][j]);
    scanf("%d ", &matrix2[i][j]);
    

    Change the format specifiers to:

    scanf("%d", &matrix1[i][j]);
    scanf("%d", &matrix2[i][j]);
    

    (Well, it’s only the second one that matters, but you might as well keep them identical.)

    A space in the format specifier matches one or more whitespaces in the input. When your code is run, the final scanf() sits there reading from stdin until it encounters a non-whitespace character (the 8 in 84), at which point it returns and your program ends.

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

Sidebar

Related Questions

Suppose I have some code that would, in theory, compile against any version of
What i want is that i want this portion of html code to be
I'm working on a pretty complex DSL that I want to compile down into
I have a portion of code that is dynamically loaded via an AJAX call
Code that is untestable really annoys me. The following things make oo-code untestable: global
The code that I want to write is like this: void MethodOnThreadA() { for
I have some template code that I would prefer to have stored in a
I have code that references a web service, and I'd like the address of
I have a large image and only want a rectangle portion of it to
Alright, so here's the portion of my code that is giving me a problem.

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.