0

[HELP] Remainder or modulus operator

Hey guys we all r familiar with the modulus operator (%) which gives us remainder.What i want is when we perform modulus operation between two numbers in which the numerator is small i want the first remainder rather than returning the same number as it is.. for example 2%7 we get the remainder 2 as the number is smaller but when we calculate in decimals we get the first remainder as 6 and the division continues so on and 6 will be the repeated remainder well i want this 6 Plz help me ..thank you :)

14th Dec 2017, 5:33 AM
Suhail Pappu
Suhail Pappu - avatar
9 Réponses
+ 2
How about this? int Remainder(int a, int b){ if (a < b){ return (a * 10) % b } return a % b } //Modify depending on language used
14th Dec 2017, 9:23 AM
blackcat1111
blackcat1111 - avatar
+ 2
The first number after the decimal when using floating point numbers is 2 when dividing 2 by 7. Where are you getting a repeating 6? And what exactly do you want to happen?
14th Dec 2017, 5:46 AM
Zeke Williams
Zeke Williams - avatar
+ 2
@Suhail Pappu Do you mean 2/12 or 1/3? Because 2/7 gives 0.28 142857 recurring, which does not contain the digit 6.
14th Dec 2017, 9:03 AM
blackcat1111
blackcat1111 - avatar
+ 2
@Suhail Pappu Wouldn't that just be 20%7?
14th Dec 2017, 9:12 AM
blackcat1111
blackcat1111 - avatar
+ 1
@Zeke Williams I think they mean 20%7 which gives 6. But 200%7 doesn't, so I'm quite lost too. 🤔
14th Dec 2017, 6:31 AM
blackcat1111
blackcat1111 - avatar
+ 1
if u divide 2 by 7 using normal division on paper u can see first it divides by 0.2 and gives the reminder 6 and if we continue further the quotient increases further but reminder goes on changes and eventually it repeats with 6 again
14th Dec 2017, 7:39 AM
Suhail Pappu
Suhail Pappu - avatar
+ 1
you are saying about quotient and i am asking about remainder and only i want upto 0.2 i.e we get the remainder as 6
14th Dec 2017, 9:10 AM
Suhail Pappu
Suhail Pappu - avatar
+ 1
yes i know but according to my problem i want 2%7 and want it to end upto one decimal place i.e 0.2 and give me the first remainder
14th Dec 2017, 9:14 AM
Suhail Pappu
Suhail Pappu - avatar
+ 1
oh my why didnt i think about the "*10" before? ah lol Anyways thanks bro for reminding me the remainder
14th Dec 2017, 9:42 AM
Suhail Pappu
Suhail Pappu - avatar