It is necessary to check the correctness of the input at the input (example: 8 is correct, but an error). I know that for c ++ you can do this:
int n; if (cin.good()){ ... } And how to do the same, but not for cin, but for scanf. Tried scanf.good (), but does not work