#include<stdio.h>
int main()
{
int x;
float peri ,area1;
scanf("%d",&x);
area(x, &peri, &area1);
printf(" %f %f ", peri, area1);
return 0;
}
int area(int r, float *per, float *are)
{
*per = 2.0 * r;
*are = 3.14 * r * r;
}
This works fine but when I try to change the input value to float
#include<stdio.h>
int main()
{
float x, peri, area1;
scanf("%f",&x);
float area(x, &peri, &area1);
printf(" %f %f ", peri, area1);
return 0;
}
float area(float r, float *per, float *are)
{
*per = 2.0 * r;
*are = 3.14 * r * r;
}
I get:
error: expected ')' before '&' token
float area( x, &peri, &area1);
should be
area( x, &peri, &area1);
You don't need to specify the return type when you are calling the function.
Also since the return type now is non-int you need to either:
Provide a function declaration like:
float area(float, float *, float *);
before main.
Also since you are not returning anything from the function you should be making its return type as void.
float area( x, &peri, &area1);
declares a function, While what you are trying to do is to call the function so it should be:
area( x, &peri, &area1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With