Knowee
Questions
Features
Study Tools

#include <stdio.h>int main() { int N, M; scanf("%d %d", &N, &M); int saplings[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { scanf("%d", &saplings[i][j]); } } printf("\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { printf("%d ", saplings[i][j]); } printf("\n"); } return 0;}

Question

#include <stdio.h>int main() { int N, M; scanf("%d %d", &N, &M); int saplings[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { scanf("%d", &saplings[i][j]); } } printf("\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { printf("%d ", saplings[i][j]); } printf("\n"); } return 0;}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a simple C program that reads in a 2D array of integers from the user and then prints out the array. Here's a step-by-step explanation:

  1. The program starts with the inclusion of the standard input/output library, stdio.h.

  2. The main function is declared, which is the entry point of the program.

  3. Two integer variables, N and M, are declared. These will hold the dimensions of the 2D array.

  4. The scanf function is used to read in the values of N and M from the user.

  5. A 2D array, saplings, of size N x M is declared.

  6. Two nested for loops are used to iterate over each element in the saplings array. The scanf function is used to read in the value of each element from the user.

  7. A newline character is printed to separate the input from the output.

  8. Two more nested for loops are used to iterate over each element in the saplings array again. This time, the printf function is used to print out the value of each element.

  9. After all elements in a row have been printed, a newline character is printed to move to the next row.

  10. The program ends with a return statement, return 0;, which indicates that the program has ended successfully.

This problem has been solved

Similar Questions

0/0

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.