C Language | Area of a Circle

Sunday 9 December 2012

In Geometry, there are a lot of shapes that has different sides and sizes but there is one shape that has no sides and that is circle. A circle has an infinity line because of its round shape. The area of a circle is the simple thing you can calculate because of its simple equation. You only need to multiply the radius and pi then multiply again the result to the radius: a = ((PI * r) * r), respectively.

To calculate the area of a circle easily I made a program out of its equation. Since we're going to use PI anywhere in the program we need to declare it globally, meaning we need to declare it out of the main program. Check out the sample code below.


    1: #include <stdio.h>
   2:  #include <conio.h>
   3:  #define PI 3.141
   4:   
   5:  int main()
   6:  {
   7:    float r, a;
   8:   
   9:    printf("Radius: ");
  10:    scanf("%f", &r);
  11:   
Related Posts Plugin for WordPress, Blogger...