Index « Previous Next »

Question

Write a function named areaRectangle, that takes length, width as parameter and returns the area of rectangle. Write a program that demonstrates the function by calling it and displays the return value.

Source Code

#include <stdio.h>

int areaRectangle(int, int);

int main()
{
    int l, b, area;
    printf("Enter the length : ");
    scanf("%d", &l);

    printf("Enter the width : ");
    scanf("%d", &b);

    area = areaRectangle(l, b);

    printf("The area of the rectangle : %d", area);

    return 0;
}

int areaRectangle(int length, int width)
{
    return length * width;
}

Output

Enter the length : 15
Enter the width : 9
The area of the rectangle : 135