If this pyramid has a 2 meters high secret room, then the total number of stones needed is 56 – 4 = 52. Input You have to read data from input file named, "input.txt". Each input has two integers, the first represents the pyramid height n, and second represents the secret room height m. Input is terminated by a sequence having n 0, m 0 which should not be processed. 1

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question
Please by using C++ compailar gdb
Question-2:
A pyramids are discovered, each has a triangular base with equal sides. An n meters high
pyramid is constructed by forming n layers of triangles using 1m' cubical stones. Then layers are
stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters
base, until the top level which has only 1 stone. You are asked to calculate the number of stones
needed to build a pyramid with the height n.
WAIT!! We just discovered that some pyramids have a secret room inside. This room is also of
the same shape and structure as the pyramid with m layers of stones removed. In order for the
room to be secret, m <n-2.
Figure 1. (a) 6 layers of stones, and (b) 6 meters high pyramid.
Example
The total number of stones needed to build a 6 meters high pyramid is
= (1+2+3+4+5+6)+( 1+2+3+4+5)+ (1+2+3+4)+ (1+2+3)+ (1+2)+ 1
= 21 + 15 + 10 + 6 + 3 +1 = 56.
Transcribed Image Text:Question-2: A pyramids are discovered, each has a triangular base with equal sides. An n meters high pyramid is constructed by forming n layers of triangles using 1m' cubical stones. Then layers are stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters base, until the top level which has only 1 stone. You are asked to calculate the number of stones needed to build a pyramid with the height n. WAIT!! We just discovered that some pyramids have a secret room inside. This room is also of the same shape and structure as the pyramid with m layers of stones removed. In order for the room to be secret, m <n-2. Figure 1. (a) 6 layers of stones, and (b) 6 meters high pyramid. Example The total number of stones needed to build a 6 meters high pyramid is = (1+2+3+4+5+6)+( 1+2+3+4+5)+ (1+2+3+4)+ (1+2+3)+ (1+2)+ 1 = 21 + 15 + 10 + 6 + 3 +1 = 56.
If this pyramid has a 2 meters high secret room, then the total number of stones needed is 56 - 4
= 52.
Input
You have to read data from input file named, "input.txt". Each input has two integers, the first
represents the pyramid height n, and second represents the secret room height m. Input is
terminated by a sequence having n= 0, m = 0 which should not be processed.
1<n< 2000000000, 0 <m< n-2
Output
You have to write output to the output file named, "output.txt". For each sequence, you are to
output one line, containing the number of stones needed
Input.txt
Output.txt
6.
56
6.
1
55
6.
2
52
4
36
100 1
171699
Transcribed Image Text:If this pyramid has a 2 meters high secret room, then the total number of stones needed is 56 - 4 = 52. Input You have to read data from input file named, "input.txt". Each input has two integers, the first represents the pyramid height n, and second represents the secret room height m. Input is terminated by a sequence having n= 0, m = 0 which should not be processed. 1<n< 2000000000, 0 <m< n-2 Output You have to write output to the output file named, "output.txt". For each sequence, you are to output one line, containing the number of stones needed Input.txt Output.txt 6. 56 6. 1 55 6. 2 52 4 36 100 1 171699
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr