To calculate an area of a circle is as easy as to calculate an area of rectangle and triangle.
First we have to know the formula of circle area.
It is:
Area = π * r2
Where: π = 22/7
r = radian or a half of diameter.
So we just need to make the program to ask only one input, it’s radian or diameter.
If we make the program to ask to enter diameter, so we have to divide the diameter with 2.
The complete syntax is shown in the example below:
#include "iostream.h"
#include "conio.h"
main()
{
int area, d, r;
cout<< "Calculate Circle Area";
cout<< "\n\nInsert long of the diameter: ";
cin>> d;
area = (22*(d/2)*(d/2)/7;
cout<< "The Area of the Circle is: "<< area;
getch();
}
see the pictures below, as the result of the program above.
0 comments:
Post a Comment