In this example, the user is asked to enter a number for radius. The program will then use the enetered radius to calculate the area of a circle.
#include <stdio.h> int main() { double r, res; printf("Enter the radius: "); scanf("%lf", &r); res = 3.14 * r * r; printf("Area of the circle is: %.2lf\n", res); return 0; }
Formula to Calculate Area of a Circle
The formula to calculate area of a circle is as following,
3.14 (value of PI) * radius * radius
First, two variables are declared of type double, namely r and res. The variable r will store the value of radius as an input in it. The variable res will store the end result. The program will then use the above mentioned formula to calculate the area of a circle. The result will then be stored in res. Eventually, it is displayed on the console.
Output
Enter the radius: 5 Area of the circle is: 78.50