Warning: sizeof(): Parameter must be an array or an object that implements Countable in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php on line 245

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php on line 245

Warning: Cannot modify header information - headers already sent by (output started at /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php:245) in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62
calculating the circumference and area of a circle: Example code in C – Coal Geology and Mining: Consulting Services

# calculating the circumference and area of a circle: Example code in C

// calculating the circumference and area of a circle
// Practice Example Program code in C

#include <stdio.h>
int main(void)
{
// Declare variables
float radius = 0.0f; // The radius of the circle
float diameter = 0.0f; // The diameter of the circle
float circumference = 0.0f; // The circumference of the circle

//initialize variables
float area = 0.0f; // The area of the circle
float Pi = 3.14159265f;

//get user input
printf(“Enter the diameter of the circle:”);
scanf(“%f”, &diameter); // Get the diameter from the user

radius = diameter/2.0f; // Calculate the radius

circumference = 2.0f*Pi*radius; // Calculate the circumference

area = Pi*radius*radius; // Calculate the area

printf(“\nThe circumference is %.2f”, circumference);

printf(“\nThe area is %.2f\n”, area);

return 0;
}