I am currently learning c , when I use a function with return using float it always gives output as zero after decimal point. eg: output is 523.000000 but it should have been 523.333333
when I change every variable to float, it gives the below when float is used for all variableerror.
#include <stdio.h>
main ()
{
float r,ans;
printf("r=");
scanf("%f",&r);
ans =volume(r);
printf("volume of sphere is %f",ans);
return 0;
}
volume(float x)
{
float v;
v= (4/3.0)*(3.14)*x*x*x;
return(v);
}
`#include <stdio.h>
// when int is used for r
main ()
{ int r;
float ans;
printf("r=");
scanf("%d",&r);
ans =volume(r);
printf("volume of sphere is %f",ans);
return 0;
}
volume(int x)
{
float v;
v= (4/3.0)*(3.14)*x*x*x;
return[output when int is used for r variable](https://i.stack.imgur.com/f6KwJ.png)(v);
}