Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
16. Write a program to print the area of a rectangle using function & return its value to main function.
/*
File: Prgrm16.c
Author: Aditya Saini
Date: Jan 17, 2021
Description: Program to print the area of a rectangle using function & return its value to
main function.
*/
#include <stdio.h>
float area_of_rectang (float, float);
int main (void)
{
float length, width;
float area;
//Input sides.
printf ("Input length: ");
scanf ("%f", &length);
printf ("Input width: ");
scanf ("%f", &width);
//Function call
area = area_of_rectang (length, width);
//Print result
printf ("Area of rectangle: %.2f", area);
};
float area_of_rectang (float length, float width)
{
float area;
//Calculate area
area = length * width;
//Return area
return area;
};
Output
Input length: 5.3
Input width: 2.7
Area of rectangle: 14.31
No comments:
Post a Comment
Please do not post spam links.