Processing math: 0%

Pages

Tuesday, 8 December 2015

Area and Circumference of a circle using C++



Algorithm:



Radius of Circle : r
Diameter of a circle : d = 2 * r
The area of a circle is : (\pi*{r^2})
Circumference of a circle is : (2*\pi * r)  or  (\pi * d)
#include "iostream"
 
using namespace std;
#define pi 3.14
 
int main ()
{
    float r,a;
    float c;
    cout << "Enter radius :" ;
    cin >> r;
    // Area of the circle
    a = pi*r*r;
 
    // Circumference of circle
    c = 2*pi*r;
 
    cout << "Area of the circle : " << a << " " <<"square meter" << endl;
    cout << "Circumference of circle : " << c << " " <<"meter" ;
 
    return (0);
}
Input: Enter radius : 4
Output: Area of the circle : 50.24 square meter
              Circumference of the circle : 25.12 meter

No comments:

Post a Comment