0
0
Cprogramming~10 mins

Function declaration and definition - Interactive Code Practice

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

Complete the code to declare a function named add that takes two integers and returns an integer.

C
int [1](int a, int b);
Drag options to blanks, or click blank then click option'
Aadd
Bsum
Ctotal
Dcalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than add.
Forgetting the semicolon at the end of the declaration.
2fill in blank
medium

Complete the code to define the function add that returns the sum of two integers.

C
int add(int a, int b) {
    return a [1] b;
}
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting the return statement.
3fill in blank
hard

Fix the error in the function declaration to correctly declare a function named multiply that takes two integers and returns an integer.

C
int multiply(int a, int b)[1]
Drag options to blanks, or click blank then click option'
A[]
B{}
C()
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces instead of a semicolon for declarations.
Using parentheses or brackets incorrectly.
4fill in blank
hard

Fill both blanks to define a function named subtract that returns the difference of two integers.

C
int [1](int a, int b) {
    return a [2] b;
}
Drag options to blanks, or click blank then click option'
Asubtract
B+
C-
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using the plus operator instead of minus.
Using the wrong function name.
5fill in blank
hard

Fill all three blanks to define a function named max_of_two that returns the greater of two integers.

C
int [1](int a, int b) {
    if (a [2] b) {
        return [3];
    } else {
        return b;
    }
}
Drag options to blanks, or click blank then click option'
Amax_of_two
B<
Ca
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Returning the wrong variable in the if block.