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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:14:14+00:00 2026-05-21T02:14:14+00:00

wondering if there is a way I can shrink this program. I don’t like

  • 0

wondering if there is a way I can shrink this program. I don’t like the look of the 5 printf/scanf pairs, but I can’t think of a way to use a for loop to shrink it. I have trouble with matching the scanf calls to the printf calls.

for(i = 1; i < 6; i++)
    printf("Enter row %d", i);

this part is easy, however, the scanf calls and assignments into the array are baffling me.

//Sums row and column
#include <stdio.h>

int main(void) {

    int a[5][5];
    int row[5] = {0}, col[5] = {0};
    int i, j;

    printf("\t--Enter a 5x5 chart--\n");
    printf("\tEnter row #1: ");
    scanf("%d %d %d %d %d", &a[0][0], &a[0][1], &a[0][2], &a[0][3], &a[0][4]);

    printf("\tEnter row #2: ");
    scanf("%d %d %d %d %d", &a[1][0], &a[1][1], &a[1][2], &a[1][3], &a[1][4]);

    printf("\tEnter row #3: ");
    scanf("%d %d %d %d %d", &a[2][0], &a[2][1], &a[2][2], &a[2][3], &a[2][4]);

    printf("\tEnter row #4: ");
    scanf("%d %d %d %d %d", &a[3][0], &a[3][1], &a[3][2], &a[3][3], &a[3][4]);

    printf("\tEnter row #5: ");
    scanf("%d %d %d %d %d", &a[4][0], &a[4][1], &a[4][2], &a[4][3], &a[4][4]);

    for(i = 0; i < 5; i++) {
            for(j = 0; j < 5; j++) {
                    row[j] += a[j][i];
                    col[j] += a[i][j];
            }
    }

    printf("\tRow sums: %d %d %d %d %d\n", row[0], row[1], row[2], row[3], row[4]);
    printf("\tColumn sums: %d %d %d %d %d\n", col[0], col[1], col[2], col[3], col[4]);

    return 0;
}
  • 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-21T02:14:15+00:00Added an answer on May 21, 2026 at 2:14 am

    Replace:

    printf("\tEnter row #1: ");
    scanf("%d %d %d %d %d", &a[0][0], &a[0][1], &a[0][2], &a[0][3], &a[0][4]);         
    ...
    printf("\tEnter row #5: ");
    scanf("%d %d %d %d %d", &a[4][0], &a[4][1], &a[4][2], &a[4][3], &a[4][4]);
    

    with:

    for (i = 0; i < 5; i++) {
        printf("\tEnter row #%d: ", i+1);
        scanf("%d %d %d %d %d", &a[i][0], &a[i][1], &a[i][2], &a[i][3], &a[i][4]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to shrink this down... but can't figure out a way to do
I'm wondering if there's a way to do what I can do below with
I think I understand unit testing. But I was wondering: is there a way
I was wondering if there a way I can pass two or more variables
I am wondering is there any way we can test the font size/color of
I'm wondering if there is a way I can bind a flex property to
I was wondering is there a way I can have my page display a
I am wondering if there is a way I can pass an updated PHP
I know that you can cache the WSDL but is there a way to
I was wondering if there was a way to do this in Hudson (or

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.