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:

  1. #include<stdio.h>: This line includes the standard input-output library.
  2. #include<conio.h>: This line includes the "conio" library for console manipulation.
  3. #define PI 3.141592: This line defines a constant named PI with a value of approximately 3.141592.
  4. int main(): The main function where the program's execution starts.
  5. float radius, area, circum;: Variables are declared to store the radius, area, and circumference.
  6. clrscr();: Clears the console screen.
  7. printf("Enter radius of circle: ");: Prompts the user to enter the radius.
  8. scanf("%f", &radius);: Reads the radius input from the user.
  9. area = PI * radius * radius;: Calculates the area of the circle using the formula area = π * radius^2.
  10. circum = 2 * PI * radius;: Calculates the circumference using the formula circumference = 2 * π * radius.
  11. printf("Area = %f\n", area);: Prints the calculated area.
  12. printf("Circumference = %f", circum);: Prints the calculated circumference.
  13. getch();: Waits for a character input to hold the output on the screen.
  14. 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.