0
0
Cprogramming~15 mins

Improving code readability - Mini Project: Build & Apply

Choose your learning style9 modes available
Improving code readability
📖 Scenario: You are working on a simple program that calculates the area of rectangles. The original code is hard to read because it uses unclear variable names and lacks spacing.
🎯 Goal: You will improve the code readability by using clear variable names, adding spacing, and organizing the code neatly. This will make the program easier to understand and maintain.
📋 What You'll Learn
Create variables with clear and descriptive names
Use proper spacing around operators
Calculate the area by multiplying width and height
Print the results clearly
💡 Why This Matters
🌍 Real World
Clear and readable code is important in real projects so that teammates and future you can easily understand what the program does.
💼 Career
Employers value programmers who write clean, readable code because it reduces bugs and makes collaboration easier.
Progress0 / 4 steps
1
Create variables for rectangle dimensions
Create two integer variables called width and height and set them to 5 and 10 respectively.
C
Need a hint?

Use int width = 5; and int height = 10; to create the variables.

2
Add a variable for area calculation
Add an integer variable called area and initialize it to 0.
C
Need a hint?

Use int area = 0; to create the area variable.

3
Calculate the area using clear expressions
Calculate the area by multiplying width and height and store the result in area. Use spaces around the multiplication operator.
C
Need a hint?

Write area = width * height; with spaces around the *.

4
Print the area with a clear message
Print the text "Area of rectangle: " followed by the value of area using printf. Use a newline at the end.
C
Need a hint?

Use printf("Area of rectangle: %d\n", area); to print the result.