Area of Circle | area of circle using c|

C PROGRAM TO FIND AREA OF CIRCLE

google-site-verification: google92f1512c4881b7f9.html

Code:

#include <stdio.h>
int main()
{
   int area_of_circle,rad;
   float PI_VALUE=3.14;
   printf("Enter radius of circle: ");
   scanf("%d",&rad);
  area_of_circle = PI_VALUE *rad*rad;
   printf("Area of circle is: %d",area_of_circle);
   return(0);
}


Explanation:

  • We are declaring the variable in integer data type.
  • To find area of circle we need the value of Pi.
  • So, we declare the value of Pi as "PI_VALUE=3.14" in float datatype.
  • We getting the radius of the circle from the user.
  • And storing the value of radius in "rad".
  • We declare it in float datatype because it a have value like point "3.14".
  • We applying the area of circle formula .
  • Area of circle=PI_VALUE*rad*rad.
  • Then we are printing the result.

Output:




Dry run :

Radius=5

Area of circle=PI_VALUE*rad*rad

Area of circle=3.14*5*5
                       =78


Proof:


  • It comes in in point but in our output it comes without point because we have given them in integer datatype.
  • An integer datatype comes without Decimal points
  • An float datatype comes with Decimal point






Comments

Post a Comment

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering