Is there any way to do this in C++ especially the range section.
answer = (0..999).select { |a| a%3 ==0 || a%5==0 }
puts answer.inject { |sum, n| sum+n }
I have created my own c++ solution but using a more standard for loop and wondered if there was a cooler way to do it?
Template metaprogramming solution:
The following assumes the lower bound of the range is 0.
The following will allow you to specify a range of numbers (e.g. 0-999, 20-400). I’m not a master of template metaprogramming so I couldn’t think of a cleaner solution (and I did this for my own benefit and practice).