C Program to Find Area and Circumference of Circle
Program
#include<stdio.h>
#include<conio.h>
#define PI 3.141592
int main()
{
float radius, area, circum;
clrscr(); // Clears the screen
printf("Enter radius of circle: ");
scanf("%f", &radius);
area = PI*radius*radius;
circum = 2*PI*r;
printf("Area = %f\n",area);
printf("Circumference = %f",circum);
getch(); // Holds the output
return 0;
}
Output of the above program :
Enter radius of circle: 5 ↲ Area = 78.539800 Circumference = 31.415920 Note: ↲ indicates ENTER is pressed.
Code Explanation:
#include<stdio.h>
: This line includes the standard input-output library.#include<conio.h>
: This line includes the "conio" library for console manipulation.#define PI 3.141592
: This line defines a constant namedPI
with a value of approximately 3.141592.int main()
: The main function where the program's execution starts.float radius, area, circum;
: Variables are declared to store the radius, area, and circumference.clrscr();
: Clears the console screen.printf("Enter radius of circle: ");
: Prompts the user to enter the radius.scanf("%f", &radius);
: Reads the radius input from the user.area = PI * radius * radius;
: Calculates the area of the circle using the formulaarea = π * radius^2
.circum = 2 * PI * radius;
: Calculates the circumference using the formulacircumference = 2 * π * radius
.printf("Area = %f\n", area);
: Prints the calculated area.printf("Circumference = %f", circum);
: Prints the calculated circumference.getch();
: Waits for a character input to hold the output on the screen.return 0;
: Indicates successful execution of the program.
Note: The use of conio.h
and its functions might not be compatible with all compilers and systems.