BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to calculate Area and Circumference of Circle

By Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to calculate area and circumference of a circle. This program is pretty simple as both the circle area and circle circumference need radius value.

Formula to calculate are and circumference of circle

Here 3.14 is the value of Pi, represented by symbol π. For the simplicity purpose, we are taking the Pi value as 3.14, to calculate accurate results take value as 22/7.

Area of circle = 3.14 * radius * radius
Circumference of circle = 2 * 3.14 * radius

Program to calculate Area and Circumference based on user input

This program takes radius value from the user. The program prompts user to enter the radius value and calculates the area and circumference of circle, based on input value.

#include <stdio.h>
int main()
{
  float Pi=3.14, area, circumference, radius;

  //Ask user to enter the radius of circle
  printf("Enter radius of circle: ");
  //Storing the user input into variable circle_radius
  scanf("%f",&radius);

  //Calculate and print the Area of circle
  area = Pi * radius * radius;
  printf("Area of circle is: %f\n",area);

  //Calculate and print the Circumference of circle
  circumference = 2 * Pi * radius;
  printf("Circumference of circle is: %f",circumference);

  return 0;
}

Output: User enters the radius value as 2 and program calculates and prints the area and circumference using this entered value.
C Program to calculate Area and Circumference of Circle
Explanation: The reason why we have taken these three variables as float is, because area and circumference needs to be float as they contain decimal values (pi value is decimal and pi value is used in both the formulas). The radius is declared float is to allow user to enter non-integer values as radius such as 1.5, 2.75 etc.

Note: If you want more accurate results then take PI value as 22/7 instead of 3.14, it would give you the exact values of area and circumference.

Related C Examples:

  • C Program to add two numbers
  • C Program to print an integer entered by a user
  • C Program to print left triangle star pattern
  • C Program to print right triangle star pattern
❮ C TutorialC Programs ❯

Comments

  1. Tumelo says

    March 22, 2016 at 5:30 PM

    can you guys help me out here.

    write a console program that calculate the area a and circuference c of the circle

    a= p x r2
    c=2 x p x r

    you can send it on my email please.

    Reply

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap