ok question was different ....we have to find total number..
On Sat, Dec 31, 2011 at 2:08 PM, atul anand <[email protected]> wrote:
> here is solution for non-decreasing number using simple recursion.
>
> static int min=0;
> static int flag=0;
> int nonDec(int num)
> {
> if(num==0)
> {
> return 0;
> }
>
> nonDec(num/10);
> if(flag==1)
> {
> return -1; // not a non-decreasing number.
> }
> if(min <= (num%10))
> {
> min=num%10;
> }
> else
> { flag=1;
> return -1;
> }
>
> return 1; // is a non-decreasing number.
>
> }
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.