hi saurav. It seems u r new to C or C++. its real simple. for inputs above 30 , the result is bound to go negative, as the datatype u r using is int .rather u should use "long int" in place of int. this should solve ur problem.if not , PM me n i will send u the sol.