———write a recursive version of function which returns the position of the first appearance of a specified digit in a positive number.count from right and starts from 1.
i.e:input 1234 and 3,output 2,input 123241 and 2,output 3.
以上都不难,可以实现,但是他又规定如果那个digit不在那个数中的话,输出0,例如:input 234 and 1,output 0.这可把我难倒了。
注意:该程序要用recursive version写。
请高手指教,很急,谢谢!
here
int fun (int n, int d)
{
int n;
if (n <= 9) return (n == d) ? 1 : 0;
if (n%9 == d) return 1;
tmp = fun(n/10, d);
return tmp ? (tmp+1) ? 0;
}
{
int n;
if (n <= 9) return (n == d) ? 1 : 0;
if (n%9 == d) return 1;
tmp = fun(n/10, d);
return tmp ? (tmp+1) ? 0;
}