首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 #include int fun(char s[]) {int n=0 ; while(*s=’0’) {n=10*n+*s-’0’;s++;} return(n); } main()
有以下程序 #include int fun(char s[]) {int n=0 ; while(*s=’0’) {n=10*n+*s-’0’;s++;} return(n); } main()
admin
2016-12-28
21
问题
有以下程序
#include
int fun(char s[])
{int n=0 ;
while(*s<=’9’&&*s>=’0’)
{n=10*n+*s-’0’;s++;}
return(n);
}
main()
{ char s[10]={’6’,’1’,’*’,’4’,
’*’,’9’,’*’,’0’,’*’);
printf("%d\n",fun(s));
}
程序的运行结果是
选项
A、61490
B、61
C、9
D、5
答案
B
解析
在fun函数中,while循环的功能是逐个取字符数组s的字符判断其是否是数字。若是则将这些数字组成一个数保存到变量n中,并返回变量n的值。所以在主函数中调用fun(s)时,将把字符数组s中的数字组成一个数输出。因为当指针s指向数组的第3位时,即字符’*’,循环条件不成立,循环结束,返回n的值。所以输出n的值为61。
转载请注明原文地址:https://kaotiyun.com/show/krDp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下语句,则对a数组元素的引用不正确的是inta[10]={0,1,2,3,4,5,6,7,8,9},*p=a;
有以下程序voidf(int*q){inti=0;for(;i
以下程序的输出结果是#includeinta[3][3]={1,2,3,4,5,6,7,8,9,},*p;main(){p=(int*)malloc(sizeof(int));f(p,a);printf("%d\n",*p);
现有如下程序段#include"stdio.h"main(){inta[5][6]={23,3,65,21,6,78,28,5,67,25,435,76,8,22,45,7,8,34,6,78,32,4,5,67,4,21,1};in
有以下程序intf(intn){if(n==1)return1;elsereturnf(n-1)+1;}main(){inti,j=0;for(i=1;i
以下数组定义中错误的是
以下程序的功能是从名为filea.dat的文本文件中逐个读入字符并显示在屏幕上。请填空。majn(){FILE*fp;charch;fp=fopen(______);ch=fgetc(fp);whle(!feof(fp)){
定义inta=5,b;,则执行表达式b=++a*--a之后,变量b的值为______。
设有定义:charp[]={‘1’,‘2’,‘3’,},*q=p;,以下不能计算出一个char型数据所占字节数的表达式是______。
随机试题
若有以下定义:chars[20]=="programming",*ps=s;则不能代表字符o的表达式是()
对阵发性室性心动过速伴明显血流动力学障碍者,首选治疗是
A.不得调剂B.应当告知处方医师,请其确认或者重新开具处方C.药师可自行修改D.应当拒绝调剂,及时告知处方医师,并应当记录,按照有关规定报告在处方调剂过程中,最关键的步骤就是药师对处方的核查。在审核的过程中,药师应该经处方审核后,认为存在用药不
实现A/D转换的核心环节是()。
城市轨道交通线网规划的主要任务是研究确定城市轨道交通发展目标和()
某一回转运动的反应釜,工艺要求在负压下工作,釜内壁需采用金属铅防腐蚀,覆盖铅的方法应为()。
借款偿还期指标适用于()。
从现实的应用形态来看,饭店员工的劳动能力主要表现为()。
学习质量的检测与评定,对深入教学研究、深化教学改革具有()作用。
Inthepasttwentyyears,hehas______greatwealthbyhardwork.
最新回复
(
0
)