Q:

C++ Program to Calculate Area of Circle using Function

belongs to collection: C++ Number Solved Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Number Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to find Area and Perimeter of Rectangl... >>
<< C++ Program to Design Simple Calculator using swit...