Read the question, write C on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read two integers and print the smaller one.
Use the ternary operator condition ? a : b rather than an if statement.
Input. Two integers a and b.
Output. The smaller integer.
Examples
Input
9 4
Output
4
Input
3 3
Output
3
Hint
- printf("%d\n", a < b ? a : b);
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <stdio.h>
int main(void) {
int a, b;
if (scanf("%d %d", &a, &b) == 2) {
printf("%d\n", a < b ? a : b);
}
return 0;
}
main.cC17 · gcc · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.