Difference between revisions of "Politeness of a number"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Figure 1)
(Figure 1)
 
Line 6: Line 6:
 
===Figure 1===
 
===Figure 1===
 
Input: 15<br>
 
Input: 15<br>
Output: 3
+
Output: 3<br>
 
Explanation:<br>
 
Explanation:<br>
 
There are only three ways to express 15 as sum of consecutive integers i.e., <br>
 
There are only three ways to express 15 as sum of consecutive integers i.e., <br>

Latest revision as of 10:31, 20 May 2019

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.