题目详情
简答题 /*--- 函数int fun(long s, int w)返回长整型变量s中第w位的值,例如调用fun(236783,1) 函数返回3,调用fun(236783,2)函数返回8.主函数main从键盘接收一个长整数给变量s,通过调用fun函数求s奇数位之和,例如数236783各奇数位数字为3,7和3,它们的和为13. 请改正程序中的错误,使它能得出正确的结果. 注意:不得增行或删行,也不得更改程序的结构. -------------------------------------------------------*/ #include <stdio.h> unsigned fun(long , int ); int main() { /***********FOUND***********/ unsigned tot, w; long s, step; printf(" 输入一个长整数:"); scanf("%ld", &s); step = s; while (step!=0) { /***********FOUND***********/ tot = fun( s ,w); w+=2; step /=100; } printf("tot=%d\n", tot); return 0; } unsigned fun(long s, int w) { int d; while(w>0) { /***********FOUND***********/ d %= 10; s /=10; w--; } return d; }

学科:C语言程序设计
时间:2024-06-28 14:48:19
相关题目
相关作业
