C are not executed in order

I am a newbie in C, but I want to learn a lot, and I wrote this very simple program in which the user is prompted to enter the number using the keyboard. Before this, the message β€œPlease enter the real number using the keyboard” should be displayed, and then a message confirming the value of the number they dialed to the user. (code below)

The problem is that when I create my executable file and run it, it first asks for the value x and displays the message "Please enter the real number using the keyboard" only after the user dialed the number! What have I done wrong? Can someone explain this strange behavior to me as I typed my instructions in good order?

#include <stdio.h> /* package to read and to write variables */

int main(void) /* main program */
{
    float x; /* declaring a real number x*/

    printf("Please type a real number with the keyboard\n");
    scanf("%f", &x); /* prompting x with the keyboard */
    /* displaying x : */
    printf("You just typed %f, congratulations !", x);
    return 0;
}
+4
1

, , . ( , \n char). , fflush(stdout), . .

+4

All Articles