This program reads the radius of a circle and calculates its area and circumference using basic arithmetic operators.
C Program
#include <stdio.h>
int main() {
float radius, area, circumference;
const float PI = 3.14159;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
circumference = 2 * PI * radius;
printf("Area = %.2f\n", area);
printf("Circumference = %.2f\n", circumference);
return 0;
}
Explanation
- The value of
PIis declared as a constant usingconst float. - Area of a circle is calculated with the formula
π × r². - Circumference is calculated with the formula
2 × π × r. %.2finprintfrounds the output to 2 decimal places for cleaner display.
Sample Output
Enter the radius of the circle: 7
Area = 153.94
Circumference = 43.98