Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background: Imagine we are building stairs out of small bricks. For the first step, we use one brick. For the second step, we stack 2

Background: Imagine we are building stairs out of small bricks. For the first step, we use one brick. For the second step, we stack 2 bricks. And for the third step, we stack 3 bricks. And so on.
With this in mind, write the function numberOfBricks(steps), which takes a non-negative integer number of steps, and returns the number of bricks that are required to create that many steps.
For example numberOfBricks(3) returns 6, which is 1+2+3.
Hint: The sum from 1 to n is called the nth triangular number. Here is a helpful formula to calculate the nth triangular number:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4. Describe three kinds of personality units that are not traits.

Answered: 1 week ago

Question

What would you do?

Answered: 1 week ago