C program to read diameter and compute Area Perimeter

Write a C program to read the diameter of the circle and compute the perimeter and area of the circle.

Problem Definition:

In this program, we will read the diameter of a circle. Next, we find the area and perimeter of a circle.

Source code of C program to read diameter and compute Area Perimeter of a Circle

#include<stdio.h>
int main()
{
  int diameter;
  float perimeter,area;
  printf("Enter the diameter of the circle: ");
  scanf("%d",&diameter);

  perimeter=diameter*3.14;        //calculates perimeter

  area=(3.14*diameter*diameter)/4;//calculates area

  printf("\nThe area of a circle is %f",area);
  printf("\nThe perimeter of a circle is %f",perimeter);
}

Output:

Case 1:

Enter the diameter of the circle: 5

The area of a circle is 19.625000

The perimeter of a circle is 15.700000

Case 2:

Enter the diameter of the circle: 3

The area of a circle is 7.065000

The perimeter of a circle is 9.420000

Program Explanation:

1. First, create 3 variables such as diameter, area, and perimeter of type float.

2. Next, ask the user to enter the value of diameter.

See also  C program to print rightmost digit of integral left-most digit of real part

3. Calculate the area of a rectangle using formula – > area = diameter * 3.142

4. Calculate the perimeter of a rectangle using formula – > perimeter= (3.14 * diameter * diameter)/4

5. Finally, display area and rectangle using printf statement.

Summary:

This tutorial discusses how to write a program to read the diameter of the circle and compute the perimeter and area of the circle. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *