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

Also check how to write this program into a function - C program to find diameter, circumference and area of circle using functions.

Input radius: 10

Output diameter = 20 units

Output circumference = 62.79 units

Output area = 314 sq. units

Happy coding ;)

Also check how to write this program into a function - C program to find diameter, circumference and area of circle using functions.

**Example:**Input radius: 10

Output diameter = 20 units

Output circumference = 62.79 units

Output area = 314 sq. units

### Required knowledge

Fundamentals of C, Data types, Talking user input in C, Properties of circle#### Diameter of circle

Diameter of a circle can be expressed by formula: 2 * radius.#### Circumference of circle

Circumference of a circle can be expressed by formula: 2 * π * radius.#### Area of circle

Area of a circle can be expressed by formula: π * r^{2}.### Program to find diameter, circumference and area of circle

/** * C program to calculate diameter, circumference and area of circle */ #include <stdio.h> int main() { float radius, diameter, circumference, area; /* * Reads radius of circle from user */ printf("Enter radius of circle: "); scanf("%f", &radius); /* * Calculates diameter, circumference and area of circle */ diameter = 2 * radius; circumference = 2 * 3.14 * radius; area = 3.14 * (radius * radius); /* * Prints all results */ printf("\nDiameter 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 :**Since the above program contains a constant value

*PI*it is always advisable to use a constant variable to represent such types of constants. You can write the above program using a predefined constant for

*PI*present in

*math.h*header file.

*math.h*header file defines a predefined constant for

*PI*and is named as M_PI.

### Program to find diameter, circumference and area of circle

/** * C program to calculate diameter, circumference and area of circle */ #include <stdio.h> #include <math.h> //Used for PI referred as M_PI int main() { float radius, diameter, circumference, area; /* * Reads radius of circle from user */ printf("Enter radius of circle: "); scanf("%f", &radius); /* * Calculates diameter, circumference and area of circle */ diameter = 2 * radius; circumference = 2 * M_PI * radius; area = M_PI * (radius * radius); /* * Prints all results */ printf("\nDiameter of circle = %.2f units.\n", diameter); printf("Circumference of circle = %.2f units.\n", circumference); printf("Area of circle = %.2f sq. units.", area); return 0; }

Output

Enter radius of circle: 10

Diameter of circle = 20.00 units.

Circumference of circle = 62.79 units.

Area of circle = 314.00 sq. units.

Diameter of circle = 20.00 units.

Circumference of circle = 62.79 units.

Area of circle = 314.00 sq. units.

**Note:**Here %.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.

Happy coding ;)

### You may also like

- Basic C programming exercises index.
- C program to calculate area of rectangle.
- C program to convert length from meter to kilometer.
- C program to convert temperature from Fahrenheit to Celsius.
- C program to convert days into years, weeks and days.
- C program to calculate power of any numbers x
^{y}. - C program to find third angle of triangle if two angles are given.
- C program to calculate area of equilateral triangle.
- C program to calculate Simple Interest.
- C program to check whether a number is even or odd.
- C program to check leap year.
- C program to check whether a character is alphabet, digit or special character.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).