# get all the right digits

• 11-27-2005
mag_chan
get all the right digits
How can i get the all right digit.... eg. input digit is 332, output is 32. Please see the below code and help me thanks

Code:

```//Get all the right digits int getRightDigit(int id)// eg. 332 {        int rtn;         if (id < 10)                 return id%10;         rtn = getRightDigit(id/10);         printf("%d",rtn);         return rtn; }```
• 11-27-2005
ssharish2005
the above code don't give u wanted, check out this

Code:

```void getRightDigit(int id) {           if(id==0)               return;           else               printf("%d  ",id%10);               getRightDigit(id/10); }```
ssharish2005
• 11-27-2005
ZuK
Don't know witch one you want.
Code:

```#include <stdio.h> //Get all the right digits //returns id if id < 10 int getRightDigit(int id) {     int div = 10;     while (( id / div )  > 10 )         div *= 10;     return id % div; } //Get all the right digits //returns 0 if id < 10 int getRightDigit1(int id) {     if ( id < 10 ) return 0;     int div = 10;     while (( id / div )  > 10 )         div *= 10;     return id % div; } int main(void) {   printf( "%d \n" , getRightDigit(332) );    printf( "%d \n" , getRightDigit1(2) );    return 0; }```
Kurt
• 11-27-2005
mag_chan
Thanks for your reply...but the code can't output 32 when i input 332...thanks
• 11-27-2005
ssharish2005
there u go
Code:

```void getRightDigit(int id) {           if           (id==0)                           return;     else               printf("%d  ",id%100);               getRightDigit(id/100); } /*my output 32  3 */```
ssharish2005
• 11-27-2005
ZuK
What's wrong with my solution ?
Kurt
• 11-27-2005
mag_chan
Sorry Kurt...It's something error in my main program, so that it's wrong return...sorry ...thanks million for your help