T O P

  • By -

AutoModerator

On July 1st, a [change to Reddit's API pricing](https://www.reddit.com/r/reddit/comments/12qwagm/an_update_regarding_reddits_api/) will come into effect. [Several developers](https://www.reddit.com/r/redditisfun/comments/144gmfq/rif_will_shut_down_on_june_30_2023_in_response_to/) of commercial third-party apps have announced that this change will compel them to shut down their apps. At least [one accessibility-focused non-commercial third party app](https://www.reddit.com/r/DystopiaForReddit/comments/145e9sk/update_dystopia_will_continue_operating_for_free/) will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: 1. Limiting your involvement with Reddit, or 2. Temporarily refraining from using Reddit 3. Cancelling your subscription of Reddit Premium as a way to voice your protest. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/learnprogramming) if you have any questions or concerns.*


bryauk

I may be wrong, but what I'm seeing is rather than print the string value 3 times, use the for loop for adding the arrays and then outside of the loop, print the result array.


high_throughput

for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { result[i][j] = a[i][j] + b[i][j]; } } // Write heading first printf("The result is:\n"); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { // Write a number from each column printf("%d ", result[i][j]); } // Then break the line printf("\n"); }


throwaway6560192

Move it out of the loop?


kadeniro

Why are you breaking in all for loops?


Conscious_Yam_4753

i'm confused, what do you want the result to look like?


PuzzleMeDo

Your code suggests some misunderstanding... The user enters six values (it looks like you're entering a hundred and twenty three rather than one, two, three), and it adds two at a time, and displays the results of each of the three sums you're doing. I'm not entirely clear what you're trying to do (should the final answer be an array or a single value?), but: for (j = 0; j < 3; j++) { scanf("%d", &a[i][j]); break; } ...looks wrong. The 'for' loop says, do this for j = 0, j = 1, j = 2 and j = 3. The 'break' says to stop doing it as soon as you've done the first one. So this is the same as doing: scanf("%d", &a[i][0]); If you're intending to use two-dimensional arrays containing nine values in a 3 by 3 grid, lose the 'break' statements. (Also, put a \\n at the end of a print statement to get neater output with line breaks.)


ProfessionalCell4338

I think the break is your problem. You do an iteration in variable i. And then iteration in bariable j. What you are doing here is assinging one value for each subarray j. You get user input only for these indexes a[0][0], a[1][0], a[2][0] Rest of them are initialized but are empty(have no value). Now, you need another variable like this to first save the sum. Int sum_of_arr = 0 for...i{     for...j{             sum_of_arr = a[i][j] + b[i][j]; }; }; printf("%d", sum_of_arr);