Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need some C programming help. I cannot figure out what is wrong. I thin

ID: 3118933 • Letter: H

Question

Hello, I need some C programming help. I cannot figure out what is wrong. I think I am close. Would you be able to help me pick out the errors? (Don't rewrite the entire code) Any and all explanations would be appreciated. Thank you!

/*Write a program that implements a two dimensional array. Prompt the user
to input 5 integer values and then calculate and store the squared values
for each user input in the array. Output the results to the user.

*/


#include<stdio.h>
#indlude <string.h>
#define size_1 5
#define size_2 2

int main()
{
   int square[size_1][size_2];

   for (int i = 0; i <=size_1; i++)
   {
       printf("Enter value %d:", (i + 1));
       scanf("%d", &square[i][0]);
       square[i][1] = square[i][0] * square[i][0];
   }
  

   for (int i = 0; i <= size_1, i++)
   {
       printf("%d %d ", square[i], square[i][1];

   }
   return 0;
}

Explanation / Answer

Program:

Errors:

printf("%d %d ", square[i], square[i][1]);

for (int i = 0; i <= size_1; i++)

Alternate:

#include<stdio.h>

#include<conio.h>

#define MAX_ROWS 3

#define MAX_COLS 4

void print_square(int[]);

void main(void) {

   int row;

   int num[MAX_ROWS][MAX_COLS] = { { 0, 1, 2, 3 },

                            { 4, 5, 6, 7 },

                            { 8, 9, 10,   11 } };

   for (row = 0; row < MAX_ROWS; row++)

      print_square(num[row]);

}

void print_square(int x[]) {

   int col;

   for (col = 0; col < MAX_COLS; col++)

      printf("%d ", x[col] * x[col]);

   printf(" ");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote