C题库(附答案)
- 格式:xls
- 大小:164.50 KB
- 文档页数:22
有以下程序段:
int n1=10,n2=20;printf(" ",n1,n2);
要求按以下格式输出n1和n2的值,每个输出行从第一列开始,
请填空.
n1=10
n2=204n1=%d\nn2=%d.
#include
void main()
{ int a,b,c;
printf("Input a,b,c:"); scanf("%d %d %d", );
printf("a=%d,b=%d,c=%d\n",a,b,c);
}4&a,&b,&c
以下sstrcpy()函数实现字符串复制,即将t所指字符串复制到
s所指的内存空间中,形成一个新的字符串s.请填空.
#include
void sstrcpy(char *s,char *t)
{ while (*s++= ① );
}
void main()
{ char str1[80],str2[]="abcdefgh";
sstrcpy( ② );
printf("%s\n", ③ );}10①*t++
②
str1,str
2
③str1
设有宏定义:
#define MYSWAP(z,x,y) {z=x;x=y;y=z;}
以下程序段通过宏调用实现变量a,b内容交换,请填空.
float a=5,b=16,c;MYSWAP( );9c,a,b
以下定义的结构体类型包含两个成员,其中成员变量info用
来存放整形数据;成员变量link是指向自身结构体的指针。
请将定义补充完整。
struct node
{ int info; link;
}11struct node*函数fun的功能是进行字母的转换.即将形参ch所表示的字母
进行大写←→小写,并将转换结果作为函数值返回.
请在程序的下划线处填入正确的内容.
#include
char fun(char ch)
{ if((ch>='a') ① (ch<='z')
return ch-'a'+'A';
if(isupper(ch))
return ch+'a'- ② ;
return ③ ;
}8&&
函数fun的功能是计算:f(x)=1+x+x^2/2!+x^3/3!+„+x^n/n!,
直到x^n/n!<10^-6.
请在程序的下划线处填入正确的内容.
#include
#include
double fun(double x)
{ double f,t;
int n=1;
f=1.0+ ① ;
t=x;
do{ n++;
t*=x/ ② ;
f+= ③ ;
}while(fabs(t)>=1e-6);
return f;
}6x下列程序中,函数fun的功能是将形参std所指结构体数组中年
龄最大者的数据作为函数值返回,并在main函数中输出.请填
空.
#include
typedef struct
{ char name[10];
int age;
}STD;
STD fun(STD *std,int n)
{ STD max,int k;
max= ① ;
for(k=1;k
if(max.age< ② )max=std[k];
return max;
}
void main()
{ STD
std[5]={"aaa",17,"bbb",16,"ccc",18,"ddd",17,"eee",15}
;
STD max;
max=fun( ③ ); printf("\nName is:%s,Age is:%d\n", ④ );
}11std[0]下列程序中,函数fun的功能是求ss所指字符串数组中长度最
短的字符串所在的行号,作为函数值返回:把其存放在形参n所
指变量中.ss所指字符串数组中共有M个字符串,且串长≤N.请
在程序的下划线处填入正确的内容.
#include
#define M 5
#define N 20
int fun(char (*ss)[N],int *n)
{ int i,j,k=0,len=N;
for(i=0;i< ① ;i++)
{ len=strlen(ss[i]);
if(i==0) *n=len;
if(len ② *n)
{ *n=len;
k=i;
}
}
return ( ③ );}
void main()
{ char
ss[M][N]={"Beijing","Shanghai","Tianjin","Chongqing",
"Wuhan"};
int n,k,i;
k=fun( ④ );
printf("\nThe length of shortest string is:%d\n",
⑤ );
printf("\nThe shortest string is:%s\n", ⑥ );
}10M
下列程序用于输出字符串的长度.请填空.
#include
int fun(char str[])
{ int num=0;
while( ① )num++;
return ( ② );
}
void main()
{ char s[30];
③ n;
scanf(" ④ ",s);
n=fun( ⑤ ); printf( ⑥ );
}8str[num]!='下列函数count用于计算子串substr在母串str中出现的次数.
请填空.
#include
int count(char str[],char substr[])
{ int x,y,z,num=0;
for(x=0;str[x]!= ① ;x++)
for(y= ② ,z=0;substr[z]==str[y];z++,y++)
if(substr[ ③ ]=='\0')
{ num++;
break;
}
return ( ④ );
}
void main()
{ char s1[30],s2[10];
int n=0;
scanf("%s",s1);
scanf("%s", ⑤ );
n= ⑥ ; printf("The substring \"%s\" is apear %d"
times in string \" %s"\n, s2,n,s1);
}8'\0'
下列函数inverse的功能是使一个字符串按逆序存放,请填空.
#include ① inverse(char str[])
{ char m;
int i,j;
for(i= ② ,j=strlen(str);i< ③ ;i++,j ④ )
{ m=str[i];
str[i]= ⑤ ;
str[j-1]= ⑥ ;
}
}7void
下列程序的功能是计算一元二次方程的根.请填空.
#include
#include < ① >
void main ( )
{float a,b,c,disc,x1,x2,p,q;
scanf("a=%f,b=%f,c=%f", ② );
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt( ③ );
x1= ④ ;x2= ⑤ ;
printf("\n\nx1=%5.2f\nx2=%5.2f\n", ⑥ );
}4math.h下列程序的功能是将键盘输入的三个实数由小到大输出.请填
空.
#include
void main ( )
{
① ;
scanf(" ② ",&a,&b,&c);
if( ③ )
{t=a;a=b;b=t;}
if(a>c)
{ ④ }
if( ⑤ )
{t=b;b=c;c=t;}
printf("%5.2f,%5.2f,%5.2f\n",a,b,c);
}5float a,b,c
下列程序的功能是将键盘输入的两个实数由小到大输出.请填
空.
#include
void main()
{
float a,b,t;
scanf( ① );
if( ② )
{t=a; ③ ; ④ ;}
printf("%5.2f,%5.3f\n",a,b);
}5"%f,%f",&a,
下列程序的功能是判断某年(年份从键盘输入)是否闰年.闰年
的条件是:1.能被4整除但不能被100整除的年,2.能被100整除
并且也能被400整除的年.请填空.
#include
void main()
{ int year,leap;
scanf( ① );
if((year%4==0 ② year%100 ③) ④ (rear%400==0))
leap=1;
else ⑤ ;
if( ⑥ )printf("%d is a leap rear\n",year);
else printf("%d is not a leap year\n",year);
}5"%d",&year