有以下程序
#include<stdio.h>
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.9
B.61490
C.61
D.5
第1题:
有以下程序 #inclUde <stdio.h> void fun(int *s,int n1,int n2) { int i,j,t; i=n1; j=n2; while(i<j) {t=s[i];s[i]=s[j];s[j]=t;i++;j--;} } main() { int a[10]={1,2,3,4,5,6,7,8,9,0},k; fun(a,0,3); fun(a,4
A.0987654321
B.4321098765
C.5678901234
D.0987651234
第2题:
有以下程序 #include <stdio.h> 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.9
B.61490
C.61
D.5
第3题:
有以下程序
#include <stdio.h>
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 ) 9
B ) 61490
C ) 61
D ) 5
第4题:
long atol(char *s)
{
long r=0;
int neg=0;
switch(*s)
{
case '-':
neg=1;
//without break
case '+':
s++;
break;
}
while(*s>='0'&&*s<='9')
{
int n=*s++-'0';
if(neg)
n=-n;
r=r*10+n;
}
return r;
}
这是C陷阱与缺陷里面的一个课后习题的程序。
希望能帮到你,别忘了采纳我的答案哦,祝你生活愉快!
第5题:
有下列程序: #include<stdi0.h> #include<stdlib.h> intfun(intn) {int*P; p=(int*)malloc(sizeof(int)); *P=n;return*P; } voidmain( ) {inta; a=fun(10);printf("%d\n",a+fun(10));} 程序的运行结果是( )。
A.0
B.10
C.20
D.出错
第6题:
本题统计字符串str中字母a出现的次数,其中str为“(7&asdfasdf873eat687al(4a”,字母a存储在字符变量c中,最后打印输出结果。
public class javal{
public static void main(String[]args){
String str="(*&7asdf adf873eat687al(4a";
char c;
int sum=0;
int i=0:
do{
c= ;
if( )
sum++:
i++:
}while( );
System.out.println("sum="+sum);
}
}
第1处:str.charAt(i)
第2处:c= =a
第3处:i<str.length
【解析】第1处获得字符串中第i个字符;第2处判断该字符是否为a;第3处为循环终止条件。
第7题:
有以下程序: #include <stdio.h> main( ) { chars[] ="Yes\n/No",*ps=s; puts(ps +4); * (pa +4) =0; puts(s); }程序运行后的输出结果是( )。
A.n/No Yes /No
B./No Yes
C./NO Yes /No
D.n/No Yes
第8题:
A、intfun(doublep){.;}
B、intfun(floatp){.;}floatfun(floatp){.;}floatfun(unsignedp){.;}intx;intx;x=fun(0);x=fun(0);
C、intfun(inti,intj=2){.;}
D、intfun(inti=2,intj=2){.;}floatfun(inti){.;}intfun(int*p){.;}cout
第9题:
有下列程序: #include<stdi0.h> voidfun(int*S,intn1,intn2) { inti,j,t; i=n1;j=n2 while(i<j){t=s[i];s[i]=s[j];s[j]=t;i++;j --;} } voidmain( ) { inta[10]={1,2,3,4,5,6,7,8,9,0),k; fun(a,0,3);fun(a,4,9);fun(a,0,9); for(k=0;k<10;k++)printf(”%d”,a[k]);printf ("\n"); } 程序的运行结果是( )。
A.0987654321
B.4321098765
C.5678901234
D.0987651234
第10题:
可以选择输入数据或空格的输入掩码是( )。
A.0
B.&;
C.9
D.?