C program to calculate area of circle - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, June 14, 2019

C program to calculate area of circle

In this tutorial we will calculate the area of circle.Whenever we find the area of ​​a circle, then we should know its radius for it.

Solution

  • In this program we will use pie and radius of a circle so we will take three variables as pie,r and area.
  • We declared these variables in float data type.
  • Then we will enter the value of pie and radius of a circle.
  • We use a logic as area=pie*r*r
  • When we use this statement the value of pie and radius multiplication of a circle will be store in area variable.
  • Then we will print the area of circle.

We can use two types for calculate the are of circle as

  1. By enter the value of pie.
  2. By constant pie.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
float pie;
float r;
float area;
clrscr();

printf("\n Enter the value of pie=");
scanf("%f",&pie);

printf("\n Enter the value of radius=");
scanf("%f",&r);

area=pie*r*r;

printf("\n The area of circle is=");
printf("%f",area);
getch();
}

Output 1:


Output 2:



C program - area of circle by constant   pie


#include<stdio.h>
#include<conio.h>
void main()
{
const float pie=3.141;
float r;
float area;
clrscr();

printf("\n Enter the value of radius=");
scanf("%f",&r);

area=pie*r*r;

printf("\n The area of circle is=");
printf("%f",area);
getch();
}

Output 1:



Output 2:



Whenever we find the area of ​​a circle, then we should know its radius for it.So we will use pie and radius of a circle so we will take three variables as pie,r and area.We can write this program by two types.

No comments:

Post a Comment