Computer Science, asked by soumyadipdas67, 11 hours ago

Jane is solving aptitude questions as she is preparing for competitive exams. She came across a question where the dimensions of a rectangle were given, and the possible number of sub-rectangles that can be created within that rectangle (including itself) had to be found. She is now wondering if a generic solution can be found for this problem. Can you write a program to help her?

Read the input from STDIN and print the output to STDOUT.

Do not print arbitrary strings anywhere in the program, as these contribute to the standard output and test cases will fail.​

Answers

Answered by mudholkaryashwant
0

across a question where the dimensions of a rectangle were given, and the possible number of sub-rectangles that can be created within that rectangle (including itself) had to be found. She is now wondering if a generic solution can be found for this problem. Can you write a program to help her?

Read the input from STDIN and print the output to STDOUT.

Do not print arbitrary strings anywhere in the program, as these contribute to the

Answered by kodurichandu13
0

Answer:

The program that give the possible number of sub-rectangles created with-in that rectangle, including that rectangle is as follows.  

Explanation:

C++ program : To count number of rectangles, in a x b grid.

Here, a and b will the length and breadth of main rectangle.

Program:

int rectCount(int a, int b)

{

return (a * b * (b + 1) * (a + 1)) / 4;

}

int main()

{

int a = 5, b = 4;

cout <  < rectCount(a,b);

return 0;

}

Check:

When, Input is given as : a = 2, b = 2

The output : 9

That is,

There will be,

  • 4 rectangles of size 1 x 1
  • 2 rectangles of size 1 x 2
  • 2 rectangles of size 2 x 1
  • 1 rectangle of size 2 x 2.

Similar questions