SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
More Flow Of Control
Exercise:
Self-test Exercises
Question:41 | ISBN:9780321531346 | Edition: 7

Question

You have a fence that is to be 100 meters long. Your fence posts are to be placed every 10 feet. How many fence posts do you need? Why is the presence of this problem in a programming book not as silly as it might seem?What problem that programmers have does this question address?

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Given data:

A fence that is to be 100 meters long and fence posts are to be placed every 10 feet. 

Off-by-one errors abound in problem solving, not just writing loops.

General reasoning from those who do not think carefully = 100 feet of fence/10 feet between posts

                                                                                          =10 posts.

So, it will leave the last 10 feet of fence without a post.

You need 11 posts to provide 10 between-the-post 10-foot intervals to get 100 feet of fence.

0 0

Discussions

Post the discussion to improve the above solution.