Difference between revisions of "Politeness of a number"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Figure 1)
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
Figure 1 and Figure 2 show examples of how the politeness of a number can be calculated.
 
Figure 1 and Figure 2 show examples of how the politeness of a number can be calculated.
  
'''Figure 1'''
+
===Figure 1===
 
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>
Line 13: Line 14:
 
Hence answer is 3<br>
 
Hence answer is 3<br>
  
'''Figure 2'''
+
===Figure 2===
 
Input: 9<br>
 
Input: 9<br>
 
Output: 2<br>
 
Output: 2<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.