Area and perimeter of a circle

Solved
mrkrass Posted messages 8 Status Membre -  
mrkrass Posted messages 8 Status Membre -
Hello everyone, I'm new to programming and I hope you can help me.
I don't know why the surface value is always zero, here is my code and thank you for the correction.


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
double rayon=0,surface=0,perimetre=0 ;
double pi=3.14;
printf("enter the radius of the circle:");
scanf("%lf",&rayon);
surface=pi*rayon*rayon;
printf("the surface of the circle is:%lf\n",surface);
perimetre=2*pi*rayon;
printf("the perimeter of the circle is:%lf\n",perimetre);

return 0;
}

1 réponse

Anonymous user
 
Hello

To read a double, you should use %lf in the format of scanf, not %d. The same goes for printf, by the way.
5
mrkrass Posted messages 8 Status Membre 1
 
Thank you, Dad, it's resolved :)
0
mrkrass Posted messages 8 Status Membre 1
 
```c #include
#include
#define PI 3.1415

int main()
{
double radius, area, perimeter;

printf("Enter the radius of the circle:");
scanf("%lf", &radius);
area = PI * radius * radius;
printf("The area of the circle is: %lf\n", area);
perimeter = 2 * PI * radius;
printf("The perimeter of the circle is: %lf\n", perimeter);


return 0;
}


I managed to get this! :) ```
1