Problem 2 from 52 programming problems book

I was using code blocks but it was giving me compiler error for c++11 was not on the list so i tried ideone’s compiler and got the correct result

https://ideone.com/zjwlWo

Here is the problem solution link: