Question

Problem 2 Width and height of 10 rectangles have been stored in two arrays called W and H. Write a C program that will pass t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Defining header for the program
#include <stdio.h>

//This function will calculate the area of all 10 rectangles and return the
// result(i.e. Array of area )
// It will also print the area of largest triangle
int *area_of_rectangles(int *widthArray, int *heightArray){
// local Array will not work here as it will be destroyed from
// memory as function call is over so cannot be returned from function
// static array has lifetime of program so it will not be destroyed till the
// execution of whole program and can be returned from function.
static int areaArray[10];
  
// i is a loop variable
// maxArea will store the area of largest rectangle
int i,maxArea = 0;
for(i=0; i<10; i++){
  
// calculating area of ith rectangle
areaArray[i] = widthArray[i]*heightArray[i];
  
// if area of current rectangle is larger than maxArea then store it in
// maxArea variable
if(areaArray[i] > maxArea){
maxArea = areaArray[i];
}
}
  
printf("Area of largest rectangle = %d \n\n", maxArea);
return areaArray;
}


int main()
{
//define array variable names
int width[10]= {12,18,5,9,17,6,6,22,5,8};
int height[10] = {10,23,3,4,11,2,9,35,4,7};
  
// area is a pointer it will store the address of areaArray (i.e Array of
// area of all rectangles)
int *area = area_of_rectangles(width,height);
  
//loop variable i
int i;
  
// It will print the area of all rectangles
printf("Array of area of all rectangles is :: \n");
for(i=0;i<10;i++){
printf("%d ",area[i]);
}
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Problem 2 Width and height of 10 rectangles have been stored in two arrays called W...
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
  • In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different...

    In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different types of known parameter lists which are either void DisplayMax(string idI, double value[], int size) or void DisplayMax(int idn, short value几int size). The first and second parameters are parallel arrays. (Parallel Arrays are two arrays whose data is related by a common index. For example: with the string array and double array, index 5 of the string array would have some name, and index...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • The both files are included. Where are these which are colorful. Point.h and point.cpp Hor this assignment you are provided the files for a class called point. Download the h and .cpp files and incl...

    The both files are included. Where are these which are colorful. Point.h and point.cpp Hor this assignment you are provided the files for a class called point. Download the h and .cpp files and include them in your project. IheじML diagram below details the class Point くくfriend>> ostream& operator.((ostream&, point&) <ごfriend::. İstream& operator:..イ1stream&-point& - : double - v doublc getX) double getYO double - sctX( double): void - set Y(double) : void - point(double-0.0, double-0.0 operator-(const point& bool perator< const...

  • QUESTIONS 13-18 PLEASE! Maximum Storage Area DUE DATE: This project is worth 10% of your Unit...

    QUESTIONS 13-18 PLEASE! Maximum Storage Area DUE DATE: This project is worth 10% of your Unit 2 grade. Please review the Project FAQ handout for format and process. Problem Situation A construction company wishes to build a rectangular enclosure to store machinery and equipment. The site selected borders on a river that will be used as one of the sides of the rectangle. Fencing will be needed to form the other three sides. The company foot high chain-link fencing. The...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Define a type which comprises a struct called "Maxima". In this struct contains two int values...

    Define a type which comprises a struct called "Maxima". In this struct contains two int values a and b. The purpose of this struct is to store the largest two int values among a set of integers. The value a is the largest number and the value b is the second largest number. In order to accomplish this task, you need to write the following functions: allzero( struct pointer ): This function sets a and b values in a given...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • Need this in C Code is given below e Dots l lah dit Problem 1. (30...

    Need this in C Code is given below e Dots l lah dit Problem 1. (30 points) Fre bendord.cto obtain the free in decimal representation For ATY. this problem we complete the code in i tive long inte ens (W written the following positive long term 123, 40, 56, 7, 8, 9, 90, 900 the frequencies of all the digits are: 0:4, 1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7: 1. 8: 1.9: 3 In this example, the free ency of...

  • These are my answere to the following questions: are they right? 1. B 2. T 3....

    These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....

  • CRBEMENo 6 (16 points) Answer the following questions about rolled steel W-beams (use the sable provided...

    CRBEMENo 6 (16 points) Answer the following questions about rolled steel W-beams (use the sable provided as necessary): Which one of the following characteristics makes a W-beam "optimal" (as i. assumed for this class)? a narrowest flange width largest section modulus lightest weight shallowest depth d. Ir the beam is bent about horizontal x-x avis and requires a minimum section modulus of 43.4 in', which of the following beams would make the "short list"? (For this question only, mark all...

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
ADVERTISEMENT