Calculate area of a circle - C Program

C program to calculate area of circle.

Solution:

In this program, accept radius of circle from user and calculate area of circle using following formula:

Area of Circle = pi * r * r

Here, pi = 3.14

#include<stdio.h>
int main()
{
     /* variable declaration part */
     int r;
     float area;
     /* Reading part */
     printf("Enter Radius : ");
     scanf("%d",&r);
     /* Processing part */
     area=3.14*r*r;
     /* Output part */
     printf("\nArea of Circle = %f",area);
     return 0;
}


Output:

area of circle

In the above output, we can fix the digit after decimal points while printing the area of circle. If we want to fix 2 digit after decimal point then use .2 (point two) in following statement.

printf("Area of Circle = .2f",area);

Following is the output after writing above statement in program.

area of circle

Similarly, you can fix digit in any program where you need.