0
0
Cprogramming~10 mins

Format specifiers - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A%d
B%c
C%f
D%s
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f for integers causes incorrect output.
Using %c prints a single character, not an integer.
2fill in blank
medium

Complete 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'
A%d
B%s
C%c
D%f
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d prints only the integer part, not the decimal.
Using %c or %s is incorrect for numbers.
3fill in blank
hard

Fix 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'
A%d
B%f
C%c
D%s
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d prints the ASCII code, not the character.
Using %s expects a string, not a single char.
4fill in blank
hard

Fill 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'
A%s
B%d
C%f
D%c
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the format specifiers causes wrong output.
Using %f for integers or strings causes errors.
5fill in blank
hard

Fill 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'
A%.2f
B%c
C%s
D%d
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f without precision prints many decimals.
Mixing up %c and %s causes wrong output.