Write a C function int rect Area int len int wid that return

Write a C function int rect Area (int len, int wid) that returns the area of a rectangle with length len and width wid. Test it with a main program that inputs the length and width of a rectangle and outputs its area. the value in the main program, not in the function. Sample Input 6 10 Sample Output The area of a 6 by 10 rectangle is 60.

Solution

#include <stdio.h>

int rectArea(int,int); //function prototype

int main(void)
{
   int length,width;
   printf(\"\ Enter the length and width of the rectangle\");
   scanf(\"%d %d \",&length,&width); //input length and width
   printf(\"\ The area of a %d by %d rectangle is %d.\",length,width,rectArea(length,width));//display area
   return 0;
}

int rectArea(int len,int wid) //function definition
{
   return len*wid;
  
}

output:

 Write a C function int rect Area (int len, int wid) that returns the area of a rectangle with length len and width wid. Test it with a main program that inputs

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site