- We will take the radius as input from the user and store it in the variable named as radius.
- To calculate diameter, circumference and area. Use
diameter = 2 * radius
,circumference = 2 * 3.14 * radius
andarea = 3.14 * radius * radius
. respectively - Now we will print the calculated value on the output screen diameter, circumference and area respectively
#include <stdio.h> int main() { float radius, diameter, circumference, area; /* taking input as radius from the user */ printf("Enter the radius of circle: "); scanf("%f", &radius); /* * Calculatio bys using the formulas */ diameter = 2 * radius; circumference = 2 * 3.14 * radius; area = 3.14 * (radius * radius); /* now output of the calculation */ printf("Diameter = %.2f units \n", diameter); printf("Circumference = %.2f units \n", circumference); printf("Area o = %.2f sq. units ", area); return 0; }
Output
Enter the radius of circle: 7
Diameter = 14.00 units
Circumference = 43.96 units
Area o = 153.86 sq. units