AIM:
To write a C++ program to find the value of a number raised to its power that demonstrates a function using call by value.
Description:
- The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function.
- In this case, changes made to the parameter inside the function have no effect on the argument.
Algorithm:
- Start the program.
- Declare the variables.
- Get two numbers as input
- Call the function power to which a copy of the two variables is passed.
- Inside the function, calculate the value of x raised to power y and store it in p.
- Return the value of p to the main function.
- Display the result.
- Stop the program.
PROGRAM:
#include<iostream> using namespace std; int areaofrect(int l,int b) { return l*b; } int main() { int l,b; cin>>l>>b; cout<<"area of rectanle :"<<areaofrect(l,b); return 0; }
EXECUTION:
Input: 7 9 Output: area of rectangle :63
Result:
Thus, Implementation of Call by Value was executed successfully.