runtime error SIGFPE

BELOW IS GIVEN THE LINK TO MY CODE .
IT IS RUNNING ON THE TERMINAL WITHOUT ANY DIFFICULTY.
BUT WHILE SUBMISSION IT IS SHOWING RUNTIME(SIGFPE) ERROR.
I WILL BE GRATEFUL IF SOMEONE HELP ME TO DETECT THE ERROR IN THIS CODE.link text

SIGFPE is usually occurs when you try to Divide something by 0 ( Zero ). So, remove the corner case where denominator is 0.
Another reason can be integer / floating point overflow, i.e. when the number exceeds integer range. You should use long long instead of int in that case