Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than
add.Forgetting the semicolon at the end of the declaration.
✗ Incorrect
The function declaration uses the function name
add as specified.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting the return statement.
✗ Incorrect
The function returns the sum of
a and b using the plus operator.3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces instead of a semicolon for declarations.
Using parentheses or brackets incorrectly.
✗ Incorrect
A function declaration ends with a semicolon
; to indicate it is only a declaration.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the plus operator instead of minus.
Using the wrong function name.
✗ Incorrect
The function name is
subtract and the operator for subtraction is -.5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Returning the wrong variable in the if block.
✗ Incorrect
The function name is
max_of_two. The condition checks if a > b, then returns a if true, else returns b.