C++ Program to Calculate Area of Circle using Function

By | 25.12.2016

Calculate Area of Circle using Function


Write a C++ Program to Calculate Area of Circle using Function. Here’s simple C++ Program to Calculate Area of Circle using Function in C++ Programming Language.


Numbers in C++


Normally, when we work with Numbers, we use primitive data types such as int, short, long, float and double, etc. The number data types, their possible values and number ranges have been explained while discussing C++ Data Types.


Here is source code of the C++ Program to Calculate Area of Circle using Function. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C++ Program to Calculate Area of Circle using Function  */

#include <iostream>
#define PI 3.14159
using namespace std;

float AreaOfCircle(float radius);
float AreaWithDiameter(float diameter);

int main()
{
    float radius,diameter,circleArea;
    char choice='0';
    cout<<"\n\t\t\tFind Area Of Circle:"<<endl;


    for(;choice!='1'&&choice!='2';)
        {
         cout<<"\n1 to Enter Radius \n";
         cout<<"2 to Enter Diameter ";
         cout<<"\n\nEnter your Choice :: ";
         cin>>choice;
         if(choice!='1'&&choice!='2')
         cout<<"\nEnter a VALID Option ";

        }

    if(choice=='1')
    {
    cout <<"\nEnter Radius To Find Area: ";
    cin>>radius;
    circleArea=AreaOfCircle(radius);
    }
    else if(choice=='2')
    {
    cout <<"\nEnter Diameter To Find Area: ";
    cin>>diameter;
    circleArea=AreaWithDiameter(diameter);

    }
    cout<<"\nArea of Circle is:->> "<<circleArea<<endl;
    return 0;
}

float AreaOfCircle(float radius)
{
    return (PI*(radius*radius));

}

float AreaWithDiameter(float diameter)
{

    return (AreaOfCircle(diameter/2));
}

OUTPUT : :


/*  C++ Program to Calculate Area of Circle using Function  */

                       Find Area Of Circle:

1 to Enter Radius
2 to Enter Diameter

Enter your Choice :: 1

Enter Radius To Find Area: 4

Area of Circle is:->> 50.2654

Process returned 0

Above is the source code for C++ Program to Calculate Area of Circle using Function which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

3 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments