编写函数f(int n)用来统计正整数n的位数(例如,n=123时函数返回3) 参考答案: ws1( int n )

[复制链接]
查看11 | 回复4 | 2012-6-7 18:16:09 | 显示全部楼层 |阅读模式
至少一位,那么这个更简单int f( int n ){ int i=1; while(n/10)
i++; return i;} 很大的数,只能用字符串或者数组,那么统计数组的长度就可以,呵呵...
回复

使用道具 举报

千问 | 2012-6-7 18:16:09 | 显示全部楼层
int ws1(int n){int i;if(n=10){i++;n=n/10;}return i;}main(){int a;scanf("%d",&a);printf("%d",ws1(a));}...
回复

使用道具 举报

千问 | 2012-6-7 18:16:09 | 显示全部楼层
int f( int n ){ int a,x; x=n; while(x!=0) {
x=x/10;
a++;
}return a;}...
回复

使用道具 举报

千问 | 2012-6-7 18:16:09 | 显示全部楼层
int f(int n){if (n/10==0)return 1;elsereturn (1+f(n/10));}...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行