This is the code in C :
#include <stdio.h>
#define PI 3.142857
int area(float);
int main(int argc, char const *argv[])
{
float b,c;
printf("Enter the radius of the circle: ");
scanf("%f",&b);
c =area(b);
printf("The area of the circle is : %f",c);
return 0;
}
int area(float r){
float a;
a = PI * r * r;
return a;
}
For example if I write the input as 3 , it should display 28.26 but is displaying the output as 28.000000.
What is wrong in the code?
>Solution :
Return float instead of int
float area(float r){
float a;
a = PI * r * r;
return a;
}