> 其他 >
2. 编写一个函数fun,然后设计主函数调用函数fun.函数fun的功能是:计算正整数num的各位上的数字之积.
例如,若输入:252,则输出应该是:20.若输入:202,则输出应该是:0
人气:161 ℃ 时间:2020-03-29 06:38:00
解答
#include
#include
int fun(int x){
int r=1,d,c;
while (1){
d = x % 10;
r = r * d;
x = (x - d) / 10;
if (x == 0) break;
}
return r;
}
main( ){
int num;
printf("input num\n");
scanf("%d",&num);
printf("%d",fun(num));
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版