Question

In: Computer Science

Write a program 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its...

Write a program 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its area. The program consists of two functions: the main function and a function that computes and returns the area of a rectangle. The output of the program should be in the main program, not in the function.

     Sample Input: 5 8   Sample Output: The area of a 5 by 8 rectangle is 40.

Solutions

Expert Solution

Program code to copy:-

/*Program inputs the length and width of a rectangle and
outputs its area.
This program consists of two functions:
- main() function which takes length and width as input from
user and calls computeArea() function by passing length and
   width as parameter
- a computeArea() function computes and returns the
area of a rectangle.
*/
#include <stdio.h>

/*Function prototype*/
int computeArea(int l, int w);

int main()
{
   int length, width, area;
  
   /*Prompt the user to input length and width of rectangle*/
   printf("Enter the length of rectangle: ");
   scanf("%d", &length);
   printf("\nEnter the width of rectangle: ");
   scanf("%d", &width);
  
   /*Calling function to computer area by passing length and
   width as parameter*/
   area = computeArea(length, width);
  
   printf("\nThe area of a %d by %d rectangle is %d\n", length, width, area);
}

/*Function computes and returns the area of a rectangle and
receives two int type parameter */
int computeArea(int l, int w)
{
   /*Calculate area of rectangle*/
   int area = l * w;
   /*Returns area to main() function*/
   return area;
}

Screenshot of output:-


Related Solutions

Create a program to input the length and width of a rectangle and calculate and print...
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input...
4. Define the width of a rectangle as the longest length of its sides. Given a...
4. Define the width of a rectangle as the longest length of its sides. Given a closed rectangle A in Rn and a partition P of A, define the mesh of P as the maximum width of its subrectangles. Prove that a bounded function f : A → R is integrable on A if and only if, for every > 0, there is a δ > 0 such that U(f, P) − L(f, P) < for every partition P of...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double...
double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double area = 0;     area = width * length;     cout << "\n***maxArea called" << endl;          cout << "***       rectangleCount = " << Rectangle::rectangleCount << endl << endl;    } Compete this code to find the maximum area of rectangle between a,b,c
1. Write a class called Rectangle that maintains two attributes to represent the length and width...
1. Write a class called Rectangle that maintains two attributes to represent the length and width of a rectangle. Provide suitable get and set methods plus two methods that return the perimeter and area of the rectangle. Include two constructors for this class. One a parameterless constructor that initializes both the length and width to 0, and the second one that takes two parameters to initialize the length and width. 2. Write a java program (a driver application) that tests...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased
For the following exercises, use the written statements to construct a polynomial function that represents the required information.A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased by twice that amount, express the area of the rectangle as a function of x.  
C++ Question: write a program that prompts the user for the length and width of a...
C++ Question: write a program that prompts the user for the length and width of a rectangle in inches.  The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively. Sample output from one instance of the program is shown below: ```html Welcome to the Foot-To-Meter Rectangle Calculator ================================================= Enter the rectangle length in feet: 2 Enter the rectangle width in feet: 3 The rectangle dimensions are: 0.61...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT