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….

4 2 votes
Article Rating
Category: C++ Programming Number Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
bright israel

kindly assist with this question
write a program to compute the area and circumference of a circle also analyse the program

Dangare Akash Mahesh

The area of circle is ( PI*r*r )and circumference is ( 2*PI*r ).
You can create a function which will return area and another function with return value 2*PI*r. That’s all !

Ahmed Ali

Please can I have more programming question with answer

Jada Williams

THIS IS PERFECT