@Saurabh: Doesn't this turn 10 into 1? You need to count the digits in the number as you are reversing it, and replace the second while loop with a for loop with that many iterations.
Dave On Sep 21, 11:28 pm, saurabh agrawal <saurabh...@gmail.com> wrote: > @dave: > your code is producing 4526 for input=24526 instead of 2456 > Here's corrected code :) > /////////CODE/////////////// > int function(int n){ > int a[10]={0},temp=0,result =0; > while(n){ //reverse the number.. > temp=10*temp+n%10; > n/=10; > } > n=temp; > while(n){ ///remove duplicate digits... > if(a[n%10]==0){ > a[n%10]=1; > result=10*result+n%10; > } > n/=10; > } > return result;} > > ///////////////END///////////////////// > > > > On Wed, Sep 22, 2010 at 8:51 AM, Dave <dave_and_da...@juno.com> wrote: > > @Saurabh: Doesn't your code turn 123 into 321? Try this: > > > int function(int n) > > { > > int a[10]={0}; > > int result=0; > > int place=1; > > while(n){ > > if(a[n%10]==0){ > > a[n%10]=1; > > result+=(n%10)*place; > > place*=10; > > } > > n/=10; > > } > > return result; > > } > > > Dave > > > On Sep 21, 3:12 pm, saurabh agrawal <saurabh...@gmail.com> wrote: > > > int function(int n){ > > > > int a[10]={0}; > > > int result =0; > > > while(n){ > > > if(a[n%10]==0){ > > > a[n%10]=1; > > > result=10*result+n%10; > > > } > > > n/=10;} > > > > return result;` > > > > } > > > On Wed, Sep 22, 2010 at 12:39 AM, Albert <alberttheb...@gmail.com> > > wrote: > > > > Given a number find the number by eliminating the duplicate digits in > > > > the number.. > > > > > for eg: 24526 ans is 2456 > > > > ..... > > > > > int function(int n) > > > > { > > > > > . > > > > . > > > > . > > > > > } > > > > > Give all sort of solutions to this problem..... > > > > > Efficiency in the code is important .... > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Algorithm Geeks" group. > > > > To post to this group, send email to algoge...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > > <algogeeks%2bunsubscr...@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text - > > > > - Show quoted text - > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algoge...@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.