Home>

The following code that accepts input and outputs the numerical value results in unintended output.

Write the code below.

# include<stdio.h>
int main (void) {
int a [20], i, j;
/ * Input reception part * /
scanf ("% d",&j);
for (i = 0;i<j;i ++) {
  scanf ("% d",&a [i]);
  }
/ * Output part * /
for (i = 0;i<j;i ++) {
  printf ("\ n% d", a [i]);
  }
}
What this is intended to do

* It is a program that just displays the entered numerical value, but it uses a for statement intentionally. *

Now I understand
When "1 1" is entered
j = 1, and the process in the for loop of the input part is executed only once under the conditions "i = 0" and "i<1".
Since i = 0 at this point, 1 is assigned to a [0].
And the for loop is also used in the output part, and the process in the loop is executed only once under the same conditions as above.
And since i = 0 is initialized, the output result is a [i], that is, the value of a [0], so it isthat is, 1.
The actual output result will be different from what was intended, such as "326482".
This cause cannot be examined.
Also, printf for the output part
printf ("\ n% d",a [i]);
From
printf ("\ n% d",a [0]);
It is the same even if you try to rewrite it.

Someone who knows it will be saved if you can tell me.

c for