# how to get the remainder of two input number?

user input 2 numbers, the program need print out the remainder of these two numbers. can not use mod functions.

my method is use a simple loop that persorms the subtraction (big number - small number), but i found if user input negative number, this program can not print out correct answer

anyone can help me?
###### Who is Participating?

Commented:
Correction, not until, but while:

That is, first assign your return value to the absolute value of the first argument, then, WHILE the difference between the return value and the second argument is greater than the absolute value of the first argument, subtract the absolute value of the second argument from the return value.

It would be much simpler to post the code, but it would be wrong for me to just do your homework for you.
0

Commented:
Please post what you'vre done so far
0

Billing EngineerCommented:
>but i found if user input negative number, this program can not print out correct answer

so you simply have to check before your loop if the 2 values are positive numbers.
0

Commented:
The mod function always returns a value that is the same sign as the first number, regardless of the sign of the second number.

So, first determine the sign of the first argument (boolean isNeg = first<0;).

Then, subtract the absolute value of the second argument from the absolute value of the first argument until you get a value less than the first number.

Finally, if the first argument was negative, subtract the return value from zero.
0

Commented:
Also, if the absolute value of the first argument is less than the absolute value of the second argument, then just return the first argument.
0

Commented: