0
0
Cprogramming~10 mins

Using printf for output in C - 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 the text "Hello, World!".

C
#include <stdio.h>

int main() {
    [1]("Hello, World!\n");
    return 0;
}
Drag options to blanks, or click blank then click option'
Aprintf
Bprint
Ccout
Decho
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a C function.
Using 'cout' which is from C++.
Using 'echo' which is from shell scripting.
2fill in blank
medium

Complete the code to print the integer variable 'num' 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%f
B%d
C%s
D%c
Attempts:
3 left
💡 Hint
Common Mistakes
Using %s which is for strings.
Using %f which is for floating-point numbers.
Using %c which is for characters.
3fill in blank
hard

Fix the error in the printf statement to correctly print a float variable 'pi'.

C
#include <stdio.h>

int main() {
    float pi = 3.14;
    printf("Value of pi: [1]\n", pi);
    return 0;
}
Drag options to blanks, or click blank then click option'
A%c
B%s
C%d
D%f
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d which is for integers.
Using %s which is for strings.
Using %c which is for characters.
4fill in blank
hard

Fill both blanks to print a character and an integer using printf.

C
#include <stdio.h>

int main() {
    char letter = 'A';
    int number = 5;
    printf("Character: [1], Number: [2]\n", letter, number);
    return 0;
}
Drag options to blanks, or click blank then click option'
A%c
B%d
C%f
D%s
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping %c and %d.
Using %f or %s incorrectly.
5fill in blank
hard

Fill all three blanks to print a string, an integer, and a float using printf.

C
#include <stdio.h>

int main() {
    char name[] = "Bob";
    int age = 25;
    float height = 5.9;
    printf("Name: [1], Age: [2], Height: [3]\n", name, age, height);
    return 0;
}
Drag options to blanks, or click blank then click option'
A%d
B%s
C%f
D%c
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up format specifiers.
Using %c for strings or floats.