C printf does not print before scanning the next number

I got this piece of code

#include<stdio.h>
#include <stdlib.h>

int main()
{
  int i;
  int number, S;
  float MO;


  S = 0;

  for(i=0;i<10;i++)
  {
    printf("AAA %d\n", i );
    scanf("%d\n", &number);
    S = S + number;
  }

  MO = S/10;

  printf("%d , %f \n",S , MO );
  return 0;
}

when execution begins, AAA 0 is issued. Then I give my first number. After that, I expect to see AAA 1, but this will only be printed after I give the second number. Checked here

C / C ++ printf () before scanf () problem

but it seems like I can't get any of these solutions to work for me

+4
source share
4 answers

, , - , . . \n scanf() scanf() . , . C11 §7.21.6.2 5:

, () , ( ) . .

OP , . scanf(). , (Stephan Lechner), , , ( ), EOF scanf(). , OP EOF . OP , :

1 2 3 4 5 6 7 8 9 10 11

, \n scanf(). .

+4

\n scanf:

scanf("%d", &number);
+3

"\n" . scanf("%d", &number) @Michael Walz .

scanf("%d\n", &number);

  • "%d" . . stdin. , int number.

  • "\n" 0 , '\n', ' ' . , , stdin.

, (1).


2. Return '\n', scanf().

+3

stdout, , \n fflush

0

Source: https://habr.com/ru/post/1667921/


All Articles