Finding Area Of Circle In C Programming

Here’s a C program that accepts the radius of a circle and calculates and prints its area:

				
					#include <stdio.h>

#define PI 3.14159

int main() {
    float radius, area;

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    area = PI * radius * radius;

    printf("The area of the circle with radius %.2f is %.2f.\n", radius, area);

    return 0;
}

				
			
Output
C Program that Accepts Radius of a Circle and Print its Area
  • In this program, we declare a radius variable of type float to store the input radius value, and an area variable of type float to store the calculated area.

  • The user is prompted to enter the radius of the circle using the printf function, and the scanf function is used to read the input and store it in the radius variable.

  • To calculate the area of the circle, we use the formula area = PI * radius * radius, where PI is a constant defined with the value of 3.14159.

  • Finally, the program displays the calculated area of the circle using printf with the %f format specifier for floating-point values. The .2 in %.2f specifies that the area should be displayed with two decimal places.