← The C Language
Lesson 59 of 77 · 5 XP
Warm-up: is it a number? warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
scanf returns how many values it managed to read. If the input isn't a number, it returns 0:
int n;
if (scanf("%d", &n) == 1) {
printf("ok %d\n", n);
} else {
printf("not a number\n");
}
Task. Read a line. If it starts with an integer, print ok and the number separated by a space, otherwise not a number.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.