Write a C Program to enter radius of a circle and find its diameter,circumference and area - Basic C program



 


Write a C Program to enter radius of a circle and find its diameter,circumference and area


Objective:

Write a C program to input radius of a circle from user and find diameter, circumference and area of the circle. How to calculate diameter, circumference and area of a circle whose radius is given by user in C programming. Logic to find diameter, circumference and area of a circle in C.


Example


Input
Enter radius: 10


Output

Diameter = 20 units
Circumference = 62.79 units
Area = 314 sq. units


Properties of circle
Diameter, circumference and area of a circle formula is given by -
Circle formulas

D = 2r

C = 2πr

A = πr2

Where r is radius of the circle.


Logic to find diameter, circumference and area of circle


Below is the step by step descriptive logic to find diameter, circumference and area of a circle -

Input radius of circle from user. Store it in a variable say radius.
Apply the formulas to calculate diameter, circumference and area. Use diameter = 2 * radius, circumference = 2 * 3.14 * radius and area = 3.14 * radius * radius.
Print all resultant value diameter, circumference and area.


Important note: The above program contains a constant value 3.14. It is always recommended to use constant variable to represent such constants. The constant PI is already defined in math.h header file with name M_PI.

%.2f is used to print the fractional value up to two decimal places. You can also use %f to print up to default 6 decimal places.



Solution Code:

//C program to calculate diameter,circumference and area of circle by CodexRitik #include <stdio.h> int main() { float radius, diameter, circumference, area; // Input radius of circle from user printf("Enter radius of circle: "); scanf("%f", &radius); // Calculate diameter, circumference and area diameter = 2 * radius; circumference = 2 * 3.14 * radius; area = 3.14 * (radius * radius); // Print all results printf("Diameter of circle = %.2f units \n", diameter); printf("Circumference of circle = %.2f units \n", circumference); printf("Area of circle = %.2f sq. units ", area); return 0; }



Note:

This Code is Verified by CodexRitik.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

The above hole problem solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

Write a C Program to enter radius of a circle and find its diameter,circumference and area - Basic C program Write a C Program to enter radius of a circle and find its diameter,circumference and area - Basic C program Reviewed by CodexRitik on January 03, 2021 Rating: 5

No comments:

Powered by Blogger.