In this post, we will learn how to find the area of a semicircle using the C Programming language.
The area of a semicircle is defined as the total region enclosed by the semi-circle in the 2-D plane. Since, the semicircle is half of a circle, the area of the semicircle is half the area of a circle.
- Area of a semicircle = πr2/2, where ‘r’ is the radius of the circle.
We will be using the above formula in our program to calculate the area of a semicircle.
So, without further ado, let’s begin this tutorial.
C Program to Find the Area of a Semicircle
// C Program to Find the Area of a Semicircle #include <stdio.h> int main(){ float r, area; // Asking for input printf("Enter the radius of the circle: "); scanf("%f", &r); // Calculating area of semicircle area = (3.14) * (0.5) * r * r; // Display area printf("Area of the semicircle = %.2f", area); return 0; }
Output
Enter the radius of the semi-circle: 15
Area of the semicircle = 353.25
How Does This Program Work?
float r, area;
In this program, we have declared two floating data type variables named r and area.
// Asking for input printf("Enter the radius of the circle: "); scanf("%f", &r);
Then, the user is asked to enter the radius of the circle.
// Calculating area of semicircle area = (3.14) * (0.5) * r * r;
Since the area of the semi-circle is half the area of the circle, we have the Area of the semicircle = πr2/2.
// Display area printf("Area of the semicircle = %.2f", area);
The area of the semicircle is displayed on the screen using the printf() function. We have used %.2f format specifier to limit the result to 2 decimal places.
C Program to Find the Area of a Semicircle Using Function
// C Program to Find the Area of a Semicircle Using Function #include <stdio.h> float areaSemicircle(float r){ return (3.14) * (0.5) * r * r; } int main(){ float radius, area; // Asking for input printf("Enter the radius: "); scanf("%f", &radius); // Calling out the custom function area = areaSemicircle(radius); // Display output printf("Area of the semicircle = %.2f", area); return 0; }
Output
Enter the radius: 14
Area of the semicircle = 307.72
Conclusion
I hope after going through this post, you understand how to find the area of a semicircle using the C Programming language.
If you have any doubt regarding the program, then contact us in the comment section. We will be delighted to assist you.
Also Read: