C Function Area of Rectangle

By | May 19, 2020

Topic: C Function Area of Rectangle

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.

double findArea (double height, double width)
{
	return height*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);

For example,

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

 

printf("The area of Rectangle is %.2lf",findArea(h,w));

Source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>

double findArea (double height, double width)
{
	return height*width;
}



int main()
{
	double h,w;
	printf("Enter the height of the rectangle: ");
	scanf("%lf",&h);
	printf("Enter the width of the rectangle: ");
	scanf("%lf",&w);

	printf("The area of Rectangle is %.2lf",findArea(h,w));


	return 0;
}
Output:

Enter the height of the rectangle: 6
Enter the width of the rectangle: 9
The area of Rectangle is 54.00


100 Important C Language Programs for Novice C Programmers

Loading

One thought on “C Function Area of Rectangle

  1. Kawa

    Currently it is appropriate time to produce a few plans for the long run and its time to be happy. Ive learn this post and if I may just I want to suggest you some attention-grabbing issues or advice. Perhaps you can post subsequent articles relating to this blogpost. I wish to learn more things related to it!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *