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;


Circumferance and area of a circle

Leave a Comment

Your email address will not be published. Required fields are marked *