Question

12. Write a C function void rect(int *ar, int *per, int len, int wid) that computes...

12. Write a C function

void rect(int *ar, int *per, int len, int wid)

that computes the area ar and perimeter per 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 and perimeter. Output the value in the main program, not in the procedure.

Sample Input

6   10

Sample Output

Length: 6
Width: 10
Area: 60
Perimeter: 32

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void rect(int *ar, int *per, int len, int wid){
    *ar = len*wid;
    *per = 2*(len+wid);
}

int main()
{
   int ar, per, len, wid;
   scanf("%d",&len);
   scanf("%d",&wid);
   rect(&ar,&per,len,wid);
   
   printf("Length: %d\n",len);
   printf("Width: %d\n",wid);
   printf("Area: %d\n",ar);
   printf("Perimeter: %d\n",per);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
12. Write a C function void rect(int *ar, int *per, int len, int wid) that computes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please use c++ Write a program that contains a class Rectangle with two private double precision...

    please use c++ Write a program that contains a class Rectangle with two private double precision members iLength and iWidth, public set and get member functions for these two members, a two argument constructor that sets the length and width to any two user specified values and a void function area() that computes the area and then prints this value by inserting it into the cout output stream. Write a main function that ereates a Rectangle with a length of...

  • C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class...

    C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class    double rectWidth; // Local variable for width    double rectLength; // Local variable for length    string rectColor;    // Get the rectangle's width and length from the user.    cout << "This program will calculate the area of a\n";    cout << "rectangle. What is the width? ";    cin >> rectWidth;    cout << "What is the length? ";    cin >>...

  • Write programs with the following I/O (All calculations must be done in assembly x86) Input/Output are...

    Write programs with the following I/O (All calculations must be done in assembly x86) Input/Output are to be coded in C++ 2.     All sides are int type                             /|\                     -------------------------                           / | \                 |                                |                  a     /    |    \ b            |                                | width                      /     h|      \              |                                |                     /        |        \            |                                |                    --------------                ------------------------                              C                                length         Enter the values of a,b,c, and h for the triangle: 4 6   9   10     Enter...

  • The following program supposes to calculate the area of a rectangle and produce the following output....

    The following program supposes to calculate the area of a rectangle and produce the following output. Area of rectangle = 20 Unfortunately, the program has Compile-time and Run-time errors that prevent the program from running and producing the correct result. Using the table 2.1 below, allocate the error(s) on each program line. 1 class Rectangle{ 2 int length 3 Int width; 4 viod insert(int l, int w){ 5 length == l; 6 width = ww; 7 8 void calculateArea( {...

  • Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the...

    Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the following 3 methods: Method isValid() returns true if the sum of the width and height is greater than 30 Method Area() returns the area of the rectangle if it is a valid rectangle Method Perimeter() returns the perimeter of the rectangle if it is a valid rectangle The main method of MyRectangle prompts the user to enter the width and height of a rectangle...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • The statement in the following program is in the incorrect order. Rearrange the statements so that...

    The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • C++ Write code that will input a number and print the number, the square of the...

    C++ Write code that will input a number and print the number, the square of the number, and the cube of the number. Continue the operation until 999 is entered. Write code that will request the length and width of a rectangle until 0 is entered for either the length or the width. Print the area and perimeter for each set of inputs. What is the output for the following loop? int number; number = 1; while (number < 11)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT