0
0
Cprogramming~15 mins

Define macro - Mini Project: Build & Apply

Choose your learning style9 modes available
Using #define Macro in C
📖 Scenario: You are writing a simple C program that needs to use a constant value multiple times. Instead of typing the number everywhere, you want to use a macro to make your code easier to read and change.
🎯 Goal: Learn how to create and use a #define macro in C to represent a constant value.
📋 What You'll Learn
Create a macro named PI with the value 3.14
Create a variable radius with the value 5
Calculate the area of a circle using the formula PI * radius * radius
Print the calculated area
💡 Why This Matters
🌍 Real World
Macros help programmers write cleaner code by replacing repeated values with easy names. This makes programs easier to read and update.
💼 Career
Understanding macros is important for C programming jobs, especially in embedded systems, game development, and performance-critical applications.
Progress0 / 4 steps
1
Create a macro for PI
Write a #define macro named PI with the value 3.14 at the top of your program.
C
Need a hint?

Use #define PI 3.14 before int main().

2
Create a variable for radius
Inside the main function, create a variable named radius and set it to 5.
C
Need a hint?

Write int radius = 5; inside main.

3
Calculate the area using the macro
Create a variable named area inside main and set it to PI * radius * radius.
C
Need a hint?

Use float area = PI * radius * radius; to calculate the area.

4
Print the area
Write a printf statement to display the text "Area: " followed by the value of area with two decimal places.
C
Need a hint?

Use printf("Area: %.2f\n", area); to print the area with two decimals.