Answer: var ans = Enumerable.Range(0, 500).Where(i => i % 7 == 0 || i % 11 == 0).Sum();
Enumerable.Range generates a sequence of integral numbers within a specified range.
In this case it is between 0 to 500. After that inside the Where extension method we are checking if the number is divisible by 7 as well as 11 or not.Which ever number satisfies the condition, we are taking a sum of that.
Result: 27660
Asked In: Many Interviews |
Alert Moderator