Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The printf function is used in C to print formatted output to the screen.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The format specifier %d is used to print integers in C.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d which is for integers.
Using %s which is for strings.
Using %c which is for characters.
✗ Incorrect
The format specifier %f is used to print floating-point numbers in C.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping %c and %d.
Using %f or %s incorrectly.
✗ Incorrect
%c prints a character and %d prints an integer in C.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up format specifiers.
Using %c for strings or floats.
✗ Incorrect
%s prints strings, %d prints integers, and %f prints floats in C.