Difference between revisions of "Politeness of a number"
(→Question) |
(→Figure 1) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
Input: 15<br> | Input: 15<br> | ||
Output: 3<br> | Output: 3<br> | ||
− | Explanation:There are only three ways to express 15 as sum of consecutive integers i.e., <br> | + | Explanation:<br> |
+ | There are only three ways to express 15 as sum of consecutive integers i.e., <br> | ||
15 = 1 + 2 + 3 + 4 + 5<br> | 15 = 1 + 2 + 3 + 4 + 5<br> | ||
15 = 4 + 5 + 6<br> | 15 = 4 + 5 + 6<br> |
Latest revision as of 09:31, 20 May 2019
Contents
Question
Politeness of a number is defined as the number of ways it can be expressed as the sum of consecutive integers.
Figure 1 and Figure 2 show examples of how the politeness of a number can be calculated.
Figure 1
Input: 15
Output: 3
Explanation:
There are only three ways to express 15 as sum of consecutive integers i.e.,
15 = 1 + 2 + 3 + 4 + 5
15 = 4 + 5 + 6
15 = 7 + 8
Hence answer is 3
Figure 2
Input: 9
Output: 2
There are two ways of representation:
9 = 2 + 3 + 4
9 = 4 + 5
Hence answer is 2
What you need to do
Task 1
Write a program that will work out the politeness value of a given number. The program should display a suitable prompt asking the user to input the number to use and then output the politeness value.
Task 2
Test the program works by entering the number 90.
Task 3
Test the program works by entering the number 121.