C Program to Find Area of a Circle

C Program to Find Area of a Circle


 C program to find the area of a circle

The formula of the Area of a circle is 

Ï€
r
2

but some time diameter is given in this time we have to divide the diameter of a circle by 2 to get the radius.

r is a Radius and Radius is a  length from the center to the edge of a circle  

Ï€ is pi and it is a mathematic symbol whose value is 22/7 or 3.14

In this article area of the circle is calculated as below

1. C program to find the area of a circle (When the value of Ï€ is 3.14)

2. C program to find the area of a circle (When the value of Ï€ is 22/7)

3. C program to find the area of a circle using the diameter

4. C program to find the area of a circle using the function 

5. C program to find the area of a circle using #define function 


Note

This is a comment written inside //. It does not have to be written while programming. The reason for using it is for the convenience and understanding of another programmer

C program to find the area of a circle using radius (When the value of Ï€ is 3.14)

Program 

#include<stdio.h>

#include<conio.h>

void main()

{

   // Value of radius is stored in r variable

   float A, r;

   // taking input of radius from users

   printf("\n Enter radius of a circle");

   scanf("%f", &r);

   // using formula of circle Ï€

       
       A=(22*r*r)/7;

   // printing Area of circle

   printf("\n Area of circle = %f", A);

   getch();

}

   

Output

C program to print area of circle


 C program to find the area of a circle (When the value of Ï€ is 22/7)

We can use the value of Ï€ 22/7 instead of 3.14 but the answer comes slightly different and the program to find the area of a circle using the value of Ï€ is 22/7

Program 

#include<stdio.h>

#include<conio.h>

 void main()

 {

          // Value of radius stored is in r variable

          float A, r;

          // taking input of radius from user

          printf("\n Enter radius of a circle");

          scanf("%f", &r);

 //using formula of circle pi * radius * radius value of pi is 22/7

          A=(22*r*r)/7;

          // printing area of a circle

         printf("\n Area of circle = %f", A);

         getch();

 }

Output

C program to print Area of circle using radius




C program to find the area of a circle using a diameter

The diameter of a circle is the length of the circle from one edge to another edge, where the radius is a length of circle central to one edge of the circle.
So,
Radius = Diameter/2
Program 

#include<stdio.h>

#include<conio.h>

void main()

{

    float d, r, A;

    // taking input of diameter from user

    printf("\n Enter a diameter of a circle");

    scanf("%f",&d);

    // converting diameter into radius

    r=d/2;

    //using formula of circle p * radius * radius value of p is 22/7

    A=3.14*r*r;

    printf("\n Area of a circle is %f", A);

    getch();

}

Output

C program to print area of circle using diameter




C program to find the Area of circle using function

#include<stdio.h>

#include<conio.h>

void area(float); // function prototype

void main()

{

   float r;

   // taking input of radius from users

   printf("\n Enter a radius of a circle");

   scanf("%f", &r);

   area(r); // function call

   getch();

}

void area(float r)

{

   float A;

  //using formula of circle p * radius * radius value of p is 22/7

   A=3.14*r*r;

   // Printing area of circle

   printf("\n Area of a circle is %f", A);

   getch();   

}

Output

C program to find area of circle using function

C program to find the area of a circle using a #define function 

#define is used defines a macro substitution and symbolic contact  
 
Program 

#include<stdio.h>

#include<conio.h>

#define pi 3.14

void main()

{

    float r, A;

    // taking input of diameter from user

    printf("\n Enter a radius of a circle");

    scanf("%f",&r);

    /* Using area of circle area = r*r and pi is a

   variable define under #define function */

    A=pi*r*r;

    // Printing Area of circe

    printf("\n Area of a circle is %f", A);

    getch();

}


Output 



Also, check 


 

Post a Comment

0 Comments