Home>

Declare an int type array with 3 elements and store 3 integer values ​​input from the keyboard. Display the entered content.

Input Number is output before scanf () is input after printf ("Input Number>").
Furthermore, the bottom four printf are not output.

Corresponding source code
int main (void) {
    int i;
    int s [3];/* For input value confirmation * /
    for (i = 0;i<3;i ++)
        printf ("Input Number>");
        scanf ("% d \ n", s [i]);/* Substitute the input value from the keyboard into s * /
    printf ("input \ n");
    printf ("No [1] =% d \ n", s [0]);
    printf ("No [2] =% d \ n", s [1]);
    printf ("No [3] =% d \ n", s [2]);
}
What I tried

I read the reference books and sites, but couldn't solve it.
Since this is a beginner, it may be an unsightly question, but thank you.

Supplementary information (FW/tool version, etc.)

The console looks like this.

Input Number>0Input Number>-272632784 Input Number>32766

Originally, I want to output like this.

Input Number>4
Input Number>64
Input Number>23
concents inputted
No [1] = 4
No [2] = 64
No [3] = 23

  • Answer # 1

    In addition to sk-sora--ypi's point, the following corrections are required.

    If you want to loop multiple statements with a for statement, enclose the whole in {}

    Pass an int pointer instead of an int as an argument to scanf

      for (i = 0;i<3;i ++) {
            printf ("Input Number>");
            scanf ("% d",&s [i]);/* Substitute keyboard input value for s * /
        }

  • Answer # 2

    scanf ("% d", s [i]);


    Please change to
    You don't need \ n for scanf