0
0
Cprogramming~10 mins

Define macro - Interactive Code Practice

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

Complete the code to define a macro named PI with the value 3.14.

C
#define [1] 3.14
Drag options to blanks, or click blank then click option'
API
Bpi
CRadius
DCircle
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase macro names which is not a convention.
Forgetting to use #define keyword.
2fill in blank
medium

Complete the code to define a macro named MAX that returns the maximum of two values a and b.

C
#define MAX(a, b) ((([1]) > (b)) ? (a) : (b))
Drag options to blanks, or click blank then click option'
AMAX
Ba
Cx
Db
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping a and b in the comparison.
Using the macro name inside the macro definition.
3fill in blank
hard

Fix the error in the macro definition to correctly square a number x.

C
#define SQUARE(x) (([1]) * ([1]))
Drag options to blanks, or click blank then click option'
Ax
BX
Cx + 1
Dx * 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase X which is undefined.
Using expressions instead of the parameter.
4fill in blank
hard

Fill both blanks to define a macro named MIN that returns the minimum of two values a and b.

C
#define MIN(a, b) ((a) [1] (b) ? (a) : (b))
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than operator which returns the maximum instead.
Using equality or inequality operators which do not find minimum.
5fill in blank
hard

Fill all three blanks to define a macro named ABS that returns the absolute value of x.

C
#define ABS(x) ((([1]) < 0) ? -([2]) : [3])
Drag options to blanks, or click blank then click option'
Ax
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names instead of x.
Forgetting to negate x when it is negative.