阅读以下程序:#includevoid main(){int x;scanf("%d",&x);if(x--<5)printf("%d", x);elseprintf("%d", x++);}程序运行后,如果从键盘上输入5,则输出结果是()。
A.4
B.5
C.3
D.6
A.4
B.5
C.3
D.6
第1题
阅读以下程序:
include<iostream.h>
void main()
{
static int a[][3]={9,7,5,3,1,2,4,6,8};
int i,j,s1=0,s2=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i==j)s1=sl+a[i][j];
if(i+j==2)s2=s2+a[i][j];
}
cout<<s1<<","<<s2<<endl;
}
则该程序的输出结果为【 】。
第2题
A.5
B.6
C.7
D.8
第3题
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。
【说明】
以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。
【程序】
include <stdio.h>
include <stdlib.h>
FILE *cp;
char fname[20], buf[100];
int NUM;
struct key
{ char word[10];
int count;
}keyword[]={ "if", 0, "char", 0, "int", 0,
"else", 0, "while", 0, "return", 0};
char *getword (FILE *fp)
{ int i=0;
char c;
while((c=getc(fp))!= EOF &&(1));
if(c==EOF)
return (NULL);
else
buf[i++]=c;
while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )
buf[i++]=c;
buf[i]='\0';
return(buf);
}
void lookup(char *p)
{ int i;
char *q, *s;
for(i=0; i<NUM; i++)
{ q=(2);
s=p;
while(*s && (*s==*q))
{ (3))
if((4))
{ keyword[i].count++;
break;
}
}
return;
}
void main()
{ int i;
char *word;
printf("lnput file name:");
scanf("%s", fname);
if((cp=fopen(fname, "r"))==NULL)
{ printf("File open error: %s\n", fname);
exit(0);
}
NUM=sizeof(keyword)/sizeof(struct key);
while((5))
lookup(word);
fclose(cp);
for(i=0;i<NUM;i++)
printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);
}
第4题
有以下程序 #include <stdio.h> int fun(int a, int b) { if(b==0) return a; else return(fun(-a,-b)); } main() { printf("%d\n",fun(4,2)); } 程序的运行结果是______。
A.1
B.2
C.3
D.4
第5题
有以下程序
#include<stdio.h>
#include<string.h>
main()
{char a[10]=”abcd”;
prinff(“%d,%d\n”,strlen(A),sizeof(A));
}
程序运行后的输出结果是
A.7,4
B.4,10
C.8,8
D.10,lO
第6题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
编写程序,对于从键盘输入的3个实数a、b、c,计算实系数一元二次方程的根并输出所求的根。
【函数】
include<sldio.h>
include<sldlib.h>
include<math.h>
Main()
{
float a,b,c,delta,x1,x2;
printf("Enter a,b,c");
scanf("%f%f%f",&a,&b,&c));
if((1))
if((2))
printf("Input error!\n");
else
printf("The single root is%f\n",(3));
else
{
delta=b*b-4*a*c;
if((4))
{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("x1=%8.2f\nx2=%8.2f\n",x1,x2,);
}
else if(delta==0)
printf("x1=x2=%8.2f\n",(5);
else
{
Printf("z2=%8.2f+%8.2f*i\n",-b/(2*a),sqrt(-delta)/)(2*abs(a)));
Printf("z2=%8.2f-%8.2f*i\n",-b/(2*a),sqrt(-delta)/(2*abs(a)));
}
}
}
第7题
有以下程序
#include <stdio.h>
main()
{ char a,b,c;
b=’1’; c=’A’;
for(a=0; a<6; a++)
{ if (a%2) putchar(b+a);
else putchar(c+a);
}
}
程序运行后的输出结果是
A) 1B3D5F
B) ABCDEF
C) A2C4E6
D) 123456
第8题
以下程序: #include<stdio.h> #include<string.h> main() {char str[]="abcd\n\123\xab"; printf("%d",(str)); } 运行后的输出结果是()。
A.10
B.9
C.7
D.14
第9题
有以下程序: include<stclio.h> main() { char c; while((c=getchar())!=?)putchar(--c); } 程序运行时,如果从键盘输入:Y?N?<回车>,则输出结果为【 】。
第10题
A.ABCDE\0FG\0IJK
B.ABCDIJK
C.IJK
D.EFGIJK