Declaration of n and answer

In the not so easy maths problem,if I initialise n and ans along with t, I get a wrong answer but if I iniitialise them inside the while(t–),I get a right answer. Why is that?

@aiman.mumtaz hi,t here refers to test cases so in each test case ans is different according to input of that test case and if you declare ans outside while t- - than it will be global variable so behave as single variable for each test case to usi me changes hote jayenge ,islie hm har test case me nya varisble ans lerhe hai taki ans har test case ke lie alg rhe.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.