Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the function greet.
C
#include <stdio.h> void greet() { printf("Hello!\n"); } int main() { [1]; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses when calling the function.
Using incorrect syntax like brackets or keywords.
✗ Incorrect
To call a function in C, you write its name followed by parentheses, like
greet().2fill in blank
mediumComplete the code to call the function add with arguments 5 and 3.
C
#include <stdio.h> int add(int a, int b) { return a + b; } int main() { int result = [1]; printf("%d\n", result); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of parentheses for arguments.
Using brackets or braces instead of parentheses.
✗ Incorrect
To call a function with arguments, use the function name followed by parentheses containing the arguments separated by commas, like
add(5, 3).3fill in blank
hardFix the error in the function call to multiply with arguments 4 and 7.
C
#include <stdio.h> int multiply(int x, int y) { return x * y; } int main() { int product = multiply[1]; printf("%d\n", product); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses entirely.
✗ Incorrect
Function arguments must be inside parentheses separated by commas, like
multiply(4, 7).4fill in blank
hardFill both blanks to call the function divide with arguments 10 and 2, and store the result in result.
C
#include <stdio.h> double divide(double a, double b) { return a / b; } int main() { double [1] = [2]; printf("%.2f\n", result); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one printed.
Swapping the arguments in the function call.
✗ Incorrect
You store the function call
divide(10, 2) in the variable result.5fill in blank
hardFill all three blanks to call the function power with base 3 and exponent 4, store the result in res, and print it.
C
#include <stdio.h> int power(int base, int exp) { int result = 1; for (int i = 0; i < exp; i++) { result *= base; } return result; } int main() { int [1] = [2]; printf("%d\n", [3]); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and print.
Calling the function with wrong arguments.
✗ Incorrect
The variable
res stores the result of power(3, 4), and we print res.