C++ Program to calculate area of circle

Simple C++ program to calculate area of circle: Area of circle is pi*r*r. We have used this to calculate area of circle.
#include<iostream>
using namespace std;
int main()
{
 float r;
 float pi=3.14,area;
 cout<<"Enter radius of circle ";
 cin>>r;
 area=pi*(r*r);
 cout<<"Area of circle= "<<area<<endl;
 return 0;
}
Another C++ program to calculate area of circle using function
#include<iostream>
using namespace std;
float AreaOfCircle(float r)
{
 float pi=3.14,area;
 area=pi*r*r;
 return area;
}
int main()
{
     float r,area;
     cout<<"Enter radius of circle: ";
     cin>>r;
     area=AreaOfCircle(r);
     cout<<"Area of circle = "<<area;
 return 0;
} 
Another C++ Program by defining pi
In the given below program we have used #define macros to define pi as 3.14.
#include<iostream>
using namespace std;
#define pi 3.14
int main()
{
     float r,area;
     cout<<"Enter radius of circle: ";
     cin>>r;
     area=pi*r*r;
     cout<<"Area of circle = "<<area;
 return 0;
}
 

Popular posts from this blog