I'm trying to write a function to calculate diameter, circumference and area of circle whereby the function has no argument but has return value. The diameter is coming up fine but circumference and circle area results are way off and the results are also equal to each other! Is there something wrong with my variable declaration or elsewhere? Thanks!
ps: also getting the exactly same wrong results when I'm trying to tackle the same problem through a function with no return val but with an argument.
Code:
#include<stdio.h>
int radius();
int main()
{
int num;
num = radius();
printf("Diameter is %d\n", num * 2);
printf("Circumference is %d\n", 2 * 3.14 * num);
printf("Area is %d\n", 3.14 * num * num);
}
int radius()
{ int x;
printf("Enter the radius: ");
scanf("%d", &x);
return x;
}