# how to get difference of digits

• 12-20-2001
Leeman_s
how to get difference of digits
ok, say we have number 21. difference is 1.

23, difference is -1.

what is a mathematical way, only using the number 23, to get the difference of the digits. If there is no mathematical way, then how do you extract part of an int? i would really like a mathematical way though.
• 12-20-2001
Uraldor
Code:

```#include <stdio.h> int Difference(int num) {         int i1 = num % 10;         int i2 = num / 10;         return(i2 - i1); } void main() {         printf("difference between 45 is %d\n", Difference(45)); }```
• 12-20-2001
Leeman_s
yes
im so stupid sometimes, i got it
• 12-20-2001
Uraldor
sometimes it's hard to see coz you're looking so hard :) dont worry mate, we've all been there.

U.
• 12-20-2001
quzah
Quote:

sometimes it's hard to see coz you're looking so hard dont worry mate, we've all been there.

U.
Indeed. For example, I'm sure you really meant to use 'int main( void )' instead of 'void main( void )' in your code example:

Quote:

Code:

```void main() {         printf("difference between 45 is %d\n", Difference(45)); }```

It's ok, lots of people do it. (Not me, but lots still do...)

Quzah.
• 12-20-2001
Uraldor
hehe.. how picky!

I agree.. i should have used int main(void)... that is what i always do...

so why the hell did i have it that way?? well, i was in the middle of modifying someone else's code to help them with a problem...i copied and pasted from there to give an example. it's not how you would ever find it in my code

needless to say, the point of the post was the Difference() function, not the niceties of how to properly declare and use the main function.

have a great day
U.