#include <stdio.h>
#define PI 3.14
/* C program to Input integer radius and find area of Circle. */
int main()
{
int r;
float areaCircle=0.0;
/* Take input radius from user using scanf function */
printf("Enter a radius for Circle.\n");
scanf("%d", &r);
/* calculate Area of Circle */
areaCircle=PI*r*r;
printf("\nRadius of Circle = %d", r);
printf("\nValue of PI= %.2f",PI);
printf("\n Area of Circle=%.2f",areaCircle);
return 0;
}
Output:
Enter a radius for Circle
2
Radius of Circle =2
Value of PI=3.14
Area of Circle=12.56
Explanation:
1. #define PI 3.14
Define the pre-processor directive PI which store the constant value for PI i,e. 3.14.
2.
int r;
float areaCircle=0.0;
Variable r is declared as int to store integer radius value entered by user.
The areaCircle is declared as float variable for to store area of Circle, initially it is assigned to 0.0 value.
3. printf("Enter a radius for Circle.\n");
scanf("%d", &r);
The above printf() function Displays the message : "Enter a radius for Circle." on console.
User entered the value for radius is.
2
scanf("%d", &r); function scan/store the integer value 2 in the vriable r.
now the radius of circle is 2 i.e. r=2
4. areaCircle=PI*r*r;
Calculate the area of circle.
Here values of PI=3.14,r=2
areaCircle=3.14*2*2
areaCircle=12.56
5. printf("\nRadius of Circle = %d", r);
printf("\nValue of PI= %.2f",PI);
printf("\n Area of Circle=%.2f",areaCircle);
Above printf() function shows output.
Radius of Circle =2
Value of PI=3.14
Area of Circle=12.56