Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print an integer variable using printf.
C
#include <stdio.h> int main() { int num = 10; printf("[1]\n", num); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f for integers causes incorrect output.
Using %c prints a single character, not an integer.
✗ Incorrect
The %d format specifier is used to print integers in C.
2fill in blank
mediumComplete the code to print a floating-point number with printf.
C
#include <stdio.h> int main() { float pi = 3.14f; printf("[1]\n", pi); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d prints only the integer part, not the decimal.
Using %c or %s is incorrect for numbers.
✗ Incorrect
The %f format specifier is used to print floating-point numbers in C.
3fill in blank
hardFix the error in the code to correctly print a character.
C
#include <stdio.h> int main() { char letter = 'A'; printf("[1]\n", letter); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d prints the ASCII code, not the character.
Using %s expects a string, not a single char.
✗ Incorrect
The %c format specifier is used to print a single character in C.
4fill in blank
hardFill both blanks to print a string and an integer correctly.
C
#include <stdio.h> int main() { char name[] = "Bob"; int age = 25; printf("Name: [1], Age: [2]\n", name, age); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the format specifiers causes wrong output.
Using %f for integers or strings causes errors.
✗ Incorrect
%s prints strings and %d prints integers in C.
5fill in blank
hardFill all three blanks to print a float with two decimals, a character, and a string.
C
#include <stdio.h> int main() { float price = 9.99f; char grade = 'A'; char product[] = "Book"; printf("Price: [1], Grade: [2], Product: [3]\n", price, grade, product); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f without precision prints many decimals.
Mixing up %c and %s causes wrong output.
✗ Incorrect
%.2f prints a float with 2 decimal places, %c prints a character, and %s prints a string.