I am getting error in pattern 31

Please check the following code for pattern 31. This code works well in case of values of n upto 9. But it starts showing error as soon as I enter two digit numbers like 10, 11…, 15, etc. Please explain why.


Here is the code.


@pssharma1410 Please reply.