C Program to Calculate the Area and Circumference of a Circle

Question:
Write a C Program to find the area and circumference of a circle.

The program simply calculates the area and circumference of a circle using its formula. Although the value PI is already defined with preprocessor directives. It takes that value if PI is used anywhere in the program.

You can check out the following if you do not know about the operators as this program uses operators.


C Program to Calculate the Area and Circumference of a Circle

Source Code:

//Find the area and circumference of a circle

#include <stdio.h>
#include <conio.h>

//Defining the pi value
#define PI 3.142857

void main()
{
  int r;
  float area, circum;

  printf("Enter the radius of a circle: ");
  scanf("%d", &r);

 //calculate the area
  area = PI * r * r;
  printf("Area of a circle: %f ", area);

 //calculate the circumference
  circum = 2 *PI * r;
  printf("\n Circumference of a circle: %f ", circum);

  getch();
}

The output of calculating the area and circumference of a circle in C.

Enter the radius of a circle: 5
Area of a circle: 78.571426
Circumference of a circle: 31.428570