In this tutorial, you will learn how to write a C program to calculate area and circumference of a circle. This program is pretty simple as both the circle area and circle circumference need radius value.
Formula to calculate are and circumference of circle
Here 3.14 is the value of Pi, represented by symbol π. For the simplicity purpose, we are taking the Pi value as 3.14, to calculate accurate results take value as 22/7.
Area of circle = 3.14 * radius * radius Circumference of circle = 2 * 3.14 * radius
Program to calculate Area and Circumference based on user input
This program takes radius value from the user. The program prompts user to enter the radius value and calculates the area and circumference of circle, based on input value.
#include <stdio.h>
int main()
{
float Pi=3.14, area, circumference, radius;
//Ask user to enter the radius of circle
printf("Enter radius of circle: ");
//Storing the user input into variable circle_radius
scanf("%f",&radius);
//Calculate and print the Area of circle
area = Pi * radius * radius;
printf("Area of circle is: %f\n",area);
//Calculate and print the Circumference of circle
circumference = 2 * Pi * radius;
printf("Circumference of circle is: %f",circumference);
return 0;
}
Output: User enters the radius value as 2 and program calculates and prints the area and circumference using this entered value.
Explanation: The reason why we have taken these three variables as float is, because area and circumference needs to be float as they contain decimal values (pi value is decimal and pi value is used in both the formulas). The radius is declared float is to allow user to enter non-integer values as radius such as 1.5, 2.75 etc.
Note: If you want more accurate results then take PI value as 22/7 instead of 3.14, it would give you the exact values of area and circumference.
Tumelo says
can you guys help me out here.
write a console program that calculate the area a and circuference c of the circle
a= p x r2
c=2 x p x r
you can send it on my email please.