Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read two integers from the user.
C
#include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf([1], &a, &b); printf("You entered %d and %d\n", a, b); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f or %c instead of %d for integers.
Forgetting to use & before variable names in scanf.
✗ Incorrect
The scanf format specifier "%d %d" reads two integers from input.
2fill in blank
mediumComplete the code to print two floating-point numbers with two decimal places.
C
#include <stdio.h> int main() { float x = 3.1415, y = 2.7182; printf([1], x, y); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d to print floats.
Not specifying decimal places, leading to many decimals.
✗ Incorrect
The format "%.2f" prints a floating-point number with two digits after the decimal point.
3fill in blank
hardFix the error in the code to correctly read a character and an integer.
C
#include <stdio.h> int main() { char c; int n; printf("Enter a character and a number: "); scanf("%c [1]", &c, &n); printf("You entered %c and %d\n", c, n); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %c twice in scanf.
Using %f or %s for integers.
✗ Incorrect
After reading a character with %c, use %d to read an integer.
4fill in blank
hardFill both blanks to read and print two integers separated by a space.
C
#include <stdio.h> int main() { int a, b; printf("Enter two integers: "); scanf([1], &a, &b); printf([2], a, b); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifiers in scanf or printf.
Forgetting newline in printf.
✗ Incorrect
Use "%d %d" to read two integers and "%d %d\n" to print them with a newline.
5fill in blank
hardFill all three blanks to read a character, an integer, and a float, then print them.
C
#include <stdio.h> int main() { char ch; int num; float val; printf("Enter a character, an integer, and a float: "); scanf([1], &ch, &num, &val); printf([2], ch, num, val); return [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up format specifiers.
Forgetting newline in printf.
Returning 1 instead of 0.
✗ Incorrect
Use "%c %d %f" to read char, int, float; "%c %d %f\n" to print them; return 0 to end program.