C ++ Inline Function Area of Circle
Task: Write down a C++ program to use an inline function named Area(). This function will calculate and return the area of a circle. The radius of the circle is a parameter to the Area() function.
How this program with Inline Function Works?
First of all we will write a main function in C++. The user will provide an input called radius of the circle. The main function will pass the radius to the inline function as parameter.
The function Area() will accept the parameter and calculate the area of the circle by using the following formula:
Formula for calcuating Area of Circle
area of circle = 3.1415 x radius2
That is : area = 3.1415 x radius x radius
The C++ expression for the above formula is as follows:
area = 3.1415 * radius * radius;
Because we use * for multiplication in C++ programming language.
The source code for Inline function program in C++
// C++ Program to show use of Inline // functions // calculate area of circle #include<iostream> using namespace std; inline float Area(float radius) { return 3.1415 * radius * radius; } int main() { float radius; cout<<"Enter Radius of circle="; cin>>radius; cout<<"Area of circle using Inline Function is : "<<Area(radius); return 0; } /* OUTPUT of the program Inline Functions in C++ Enter Radius of circle=5.25 Area of circle using Inline Function is : 86.5876 -------------------------------- Process exited after 28.59 seconds with return value 0 Press any key to continue . . . */
Out put from another sample run
Enter Radius of circle=1.5673
Area of circle using Inline Function is : 7.71687
——————————–
Process exited after 10.9 seconds with return value 0
Press any key to continue . . .
Pingback: Python Program Fibonacci Series Function | EasyCodeBook.com
Thank you, I couldnt figure how to get it right. I tried this and it worked fine for me. Thank you again!