here
登录 | 论坛导航 -> 华新鲜事 -> 社会百科 | 本帖共有 2 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2003-09-15 10:34:20  楼主  关注此帖评分:
———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;
}
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2003-09-15 10:49:46  2楼
"return tmp ? (tmp+1) ? 0;" 这个什么意思???好像不能当双目运算符吧……
typo. another typo is
if (n%9 == d) return 1;
should be
if (n%10 == d) return 1;
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 社会百科 | 返回上一页 | 本主题共有 2 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码