user303384
user303384

Reputation: 11

Finding the Remainder after Division in C

You need to use division and remainder by 10,

Consider this example,

163 divided by 10 is 16 and remainder is 3
16 divided by 10 is 1 and remainder is 6
1 divided by 10 is 0 and remainder is 1

Notice that the remainder is always the last digit of the number that's being divided.

How can I do this in C?

Upvotes: 0

Views: 379

Answers (3)

Mark Byers
Mark Byers

Reputation: 839114

It looks like homework so I won't give you code, but I suggest you research the modulo operator and how this could be used to solve your assignment.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799390

With the modulus operator (%):

15 % 12 == 3
17 % 8 == 1

Upvotes: 1

moogs
moogs

Reputation: 8202

Use the Modulus operator:

 remainder = 163 % 10; // remainder is 3

It works for any number too:

  remainder = 17 % 8;  // remainder is 1, since 8*2=16

(This works for both C and C#)

Upvotes: 1

Related Questions