# Thread: how to get difference of digits

1. ## 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.

2. 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));
}```

3. ## yes

im so stupid sometimes, i got it

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

U.

5. 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:

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.

6. 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.

Popular pages Recent additions