# Help modulud operator

Hewlett-packard Compaq presario cq60-420...
November 2, 2009 at 23:03:46
Specs: Windows XP
 How can 0%3 =3 Please explain this.

See More: Help modulud operator

#1
November 2, 2009 at 23:45:17
 modulo, if i'm not mistaken, is fancy word for "remainder after integer division". so, 0 div by 3 is zero. the remainder is 3.modulo is short-handed as %, which can lead to confusion considering windows' use of the percent sign. But your submitted equation is: 0 % 3 and therefore yields 3 as the remainder from the division. any further elucidation will require math courses, not programming. good luc.

Report •

#2
November 3, 2009 at 01:06:20
 Thanks for your reply. I would like to create a C program to reverse the number entered by user. Here's what I have done. Is this the correct logic ?1. #include2. #include3. void main()4. {5. int x,y,z;6. scanf("%d",&x);7. while(x>0)8. {9. y=x/10;10 z=x%10;11. x=y;12. printf("%d",z);}

Report •

#3
November 3, 2009 at 03:36:32
 math classLOLModulo is a fancy name for modulo. And zero mod anything is zero.=====================================Helping others achieve escape felicityM2

Report •

Related Solutions

#4
November 3, 2009 at 05:23:12
 I always thought 0 % 3 == 0. Who said it == 3 ?

Report •

#5
November 4, 2009 at 00:12:12
 (red face) apologies. my logic wrong. not enough math\computer classes or too long since. Hoist on mey own petard Oi is. LOL. #include2. #include3. void main()4. {5. int x,y,z;6. scanf("%d",&x);7. while(x>0)8. {9. y=x/10;10 z=x%10;11. x=y;12. printf("%d",z);}my understanding is: for each digit in number, reflect the 10's complement (ie: 10 minus digit): 183 = 927 674 = 436 etc.but i'm probl'y wong. (seems to be a trend lately.)if you are fielding successive digits by division,you would need to:C = 0OUT = 0do while num>0'capture first digit in A and strip from numberA=num % 10num = num - A 'shift the main number 1 digitnum = num / 10'reverse (10's-complement) the captured digiitA = 10 - A 'modulo to make 10=0, 9=1,. etc.A = A % 10'exponentiate the digit (1's, 10's, 100's)A = A* ( C^10 )C=C+1OUT = OUT + Aloopsorry about my misinformation about modulo. seems i'm always wrong. take this into acct if using or adapting my code.

Report •

#6
November 4, 2009 at 00:22:18
 I mean numbers entered from 1,but not negative numbers.It can be 123, so answer should be 321. But when I enter a long number, the answer is not what it should be. Why?

Report •

#7
November 4, 2009 at 02:14:41
 The program that you posted tries to deal with two-digit numbers. It doesn't yet do everything it needs to do to create the reversed number. You need to think a little bit more about exactly how you do this. Concentrate on two-digit numbers first, don't complicate things.Once you have sorted out the two-digit problem, think about how you are going to do it for arbitrarily sized numbers. It will be more complicated, and you will need to start again, but carry over the knowledge and skill you've picked up in your first step.

Report •

#8
November 4, 2009 at 12:41:33
 I don't know why reversing a string would require math.=================================@echo off & setLocal EnableDELAYedExpansionif %1'==' echo done && goto :eofset N=set S=%1:loopset /a N+=1set v!N!=!S:~0,1! if "!S:~1!" neq "" ( set S=!S:~1! goto :loop )for /L %%a in (!N! -1 1) do (set R=!R!!v%%a!)echo !R!=====================================Helping others achieve escape felicityM2

Report •

#9
November 4, 2009 at 14:40:41
 Er, M2, I thought this was a question about reversing an integer in C++.

Report •

#10
November 4, 2009 at 23:59:01
 Hi klint,I guess you're right.=====================================Helping others achieve escape felicityM2

Report •