How to Find Area of Circle using C++ Programming Language

Area of Circle:

The formula for area of circle is equal to value of pi which is 3.1415 multiplied by the square of radius of circle. The radius of circle is perpendicular line from the center point of circle to any point on the boundary of circle.
A = 3.14 * r * r 
Where A  denotes area, r for radius.

Explanation of Program code:

Now you have the formula of area of circle as shown above.All you need is to apply this formula in program code.Lets start how to apply this code, first decide which formula you are going to apply, i am going to apply first one. First you have to include library files for the input and output streams.By input and output streams i mean cout and cin.
Then think how many variables you need , first you should have variable to store the value of radius.If you want to store the value of pi in any variable then define variable of type double because of decimal value.Third variable to store the value of area. For area , the variable type must be double because in the formula you can see that the result will be decimal value.For radius, the type can be integer type in case of integers values of radius.

Recommended Articles: Read this article for better under standing of Program code.
I used this loop, in order to avoid again and again execution or compiling of program code.I defined the variable redo of type character for this purpose.The statements after the statement (to display stars) are for do while loop.It is not necessary if you don't want to include this loop remove this loop.

Program Code:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
double rad , area;
 char  redo;
do
{
cout<<"Enter radius of circle "<<endl;
cin>>rad;
cout<<endl<<endl;
area = 3.1415 * rad * rad ;
cout<<"Area of circle is  =  "<<area;

cout<<endl<<"**********************************"<<endl;
cout<<" Enter y or Y for next calculation = ";
cin>>redo;
cout<<endl<<endl;

}while( redo == 'y' || redo == 'Y');

getch();
}
Output:
Enter radius of circle
2

Area of Circle is = 12.566
********************************
Enter y or Y for next calculation  =  

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.