Topic: C Function Area of Rectangle
Write a C++ function to calculate the area when height and width are given as arguments. The function will accept 2 double parameters height and width of type double and return a double(area of the rectangle).
Hint: area = height x width
Definition of C Function Area of Rectangle
First of all we will define a function that will take two arguments of type double : height and width of rectangle.
This function will return a double value that is the area of the rectangle obtained by multiplying the given height and width.
Calling the findArea() function
we can call a function that will return a value either in an assignement statement or in a printf() function. So that the returned value can be stored or used directly.
variable = function(arg1, arg2);
a = findArea(h,w);
where h and w are two variables with the given values of height and width of the rectangle. The function findArea() will calculate and return the area of rectangle which is stored in the variable a on the left side of the assignment statement.
We may print the value of the variable ‘a’.
Output: Enter the height of the rectangle: 6 Enter the width of the rectangle: 9 The area of Rectangle is 54.00
218 total views, 5 views today