 # C Programming Code Examples

## C > Beginners Lab Assignments Code Examples

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

``` program to find diameter, circumference and area of circle 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. 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. #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; } ``` 