C Program Structure: Circle area and perimeter calculation
4. Circle Structure Calculations
Define a structure named Circle to represent a circle with a radius. Write a C program to calculate the area and perimeter of two circles and display the results.
Sample Solution:
C Code:
Output:
Input details for Circle 1: Radius: 5 Input details for Circle 2: Radius: 6.3 Circle 1: Area: 78.54 Perimeter: 31.42 Circle 2: Area: 124.69 Perimeter: 39.58
Explanation:
In the exercise above,
- The "Circle" structure is defined with a member 'radius'.
- Two variables ('circle1' and 'circle2') are declared to store details for two circles.
- Two functions ("calculateArea()" and "calculatePerimeter()") are defined to calculate the area and perimeter (circumference) of a circle, respectively.
- The program prompts the user to input the radius for each circle.
- It then calculates and displays the area and perimeter for both circles.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to input the radii of two circles, compare their areas, and display both the area and perimeter of each circle.
- Write a C program to input an array of Circle structures, then sort and display the circles by their perimeters.
- Write a C program to input the radii of three circles, compute the circle with the maximum area, and display its details.
- Write a C program to input the radii of two circles and display the ratio of their areas along with both perimeters.
C Programming Code Editor:
Previous: Book details in C: Finding most expensive and lowest priced books.
Next: C Program Structure: Employee Management with Highest Salary.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.