Before going to the program first let us see how to calculate Area and Circumference of a Circle?

            To calculate Area and Circumference of a Circle we should know the formulas for Area of a Circle and Circumference of a Circle.

So the formulas are:

Area of a Circle = π × Radius × Radius 

Circumference of a Circle = 2 × π × Radius

Note: The value of π(pi) is 3.14.

Example: Let the value of radius be 5, then

Area of a Circle = 3.14 × 5 × 5 = 78.5

Circumference of a Circle = 2 × 3.14 × 5 = 31.4

Program code to calculate Area and Circumference of a Circle in C:

#include<stdio.h>
#include<conio.h> void main()
{ int r; float area, cir; clrscr(); printf("Enter radius of circle: "); scanf("%d", &r); area = 3.14 * r * r; cir = 2 * 3.14 * r; printf("n Area of a Circle : %.2f ", area); printf("n Circumference of a Circle: %.2f ", cir); getch();
}

Explanation:

  • First the computer reads the value of radius from the user and stores it in the “r” variable using the following lines:
printf("Enter radius of circle: ");
scanf("%d", &r);

 Note: %d is used to read the Integer value.

  • Then using the formulas the Area and Circumference of a Circle is calculated and stored in the “area” and “cir” variables respectively using the following lines:
area = 3.14 * r * r;
cir = 2 * 3.14 * r;
  • Finally the Area and Circumference of a Circle is printed on the screen using the following lines:
printf("n Area of a Circle : %.2f ", area);
printf("n Circumference of a Circle: %.2f ", cir);

Note: %.2f is used to print the floating-point value with only 2 decimal places.

Output:

area and circumference

TO DOWNLOAD THE PROGRAM CODE : CLICK HERE

Similar Posts