PROBLEM LINK:Author: Chandan Boruah DIFFICULTY:EASY PREREQUISITES:Maths PROBLEM:You need to print sum of all the numbers that are divisible by 10 and are less than and equal to given number N. QUICK EXPLANATION:Divide N by 10, then use formula (x(x+1)10)/2 to find the sum. EXPLANATION:
c# code:
lets say you have to print sum of numbers less than equal to number 20, divide 20 by 10 gives you 2. This is a pattern. Everytime you divide it by 10 you get count of numbers less than or equal to N that are divisible by 10. Now, x*(x+1)/2 is the sum of first x positive integers. Since, there are 2 such numbers and we have 10+20=30, we divided by 10 so we have 1+2=3. We multiply that result by 10 to get 30. This, solution comes naturally to mind, because our psychology is to think step by step. AUTHOR'S AND TESTER'S SOLUTIONS:Author's solution can be found above (c# code). Tester's solution can be found above (c# code). asked 21 Apr '16, 11:55
