0
0
Cprogramming~10 mins

Function calling - Interactive Code Practice

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

Complete 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'
Agreet()
Bgreet
Cgreet[]
Dcall greet()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses when calling the function.
Using incorrect syntax like brackets or keywords.
2fill in blank
medium

Complete 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'
Aadd{5, 3}
Badd[5, 3]
Cadd 5, 3
Dadd(5, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of parentheses for arguments.
Using brackets or braces instead of parentheses.
3fill in blank
hard

Fix 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'
A(4, 7)
B[4, 7]
C{4, 7}
D4, 7
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses entirely.
4fill in blank
hard

Fill 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'
Aresult
Bdivide(10, 2)
Cdivide(2, 10)
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one printed.
Swapping the arguments in the function call.
5fill in blank
hard

Fill 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'
Ares
Bpower(3, 4)
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and print.
Calling the function with wrong arguments.