{
if(cx!=' ')
if(cx>='a'&&cx<='z') putchar(cx-32);
else if(cx<='z'&&cx>='A') _________________; else putchar(cx); else
if(pre!=' ') putchar(cx); ________________;
} }
4-2-17、下面的程序从文本文件test.txt逐个读入字符,并显示在屏幕上。【2013年】 #include
FILE *fp;
char ch,*filename=\
if((fp=_________________ (filename,\{
printf(\exit(0); }
while(!_________________ (fp)) {
ch=fgetc(fp); putchar(ch); }
fclose(fp); }
4-2-18、以下程序的功能是:读入一行字符,以回车结束,按输入时的逆序使用单向链表进行存储,先输入的位于链表尾,然后再遍历输出链表,如输入abc↙,链表结构如下图所示,程序最后输出cba. 【2013年】
struct node {
char value;
struct node *link; }
main() {
struct node *top,*p; char c; top=NULL;
第 26 页 共 46 页
while((c=getchar())_________________) {
p=(struct node *)malloc(sizeof(struct node)); p->value=c; p->link=top;
_________________ ; }
while(top) {
p=top;
top=top->link; putchar( ⑤ ); }
}
4-2-19、函数sum(n)使用递归完成表达式的运算:sum(n)=1*2+2*3+?+n*(n+1)【2014年】
int sum(n) {
if(n==1)
return _________________ ; else
return _________________ ; }
4-2-20、函数insert(char str1[],char str2[],int idx)实现在字符串str1中的第idx个字符后插入字符串str2,如下程序的输出为:abkkkcd。【2014年】 #include
void insert(char str1[],char str2[],int idx) {
char *p,*q; p=str1; int i=0;
for(i=0;i while(*str2!='\\0') { q=p; while(*q!='\\0') _________________ ; while(q>=p) { *(q+1)=*q; _________________ ; } q++; *q=*str2; str2++; _________________ ; 第 27 页 共 46 页 } } main() { char a[10]=\char b[5]=\insert(a,b,2); printf(\} 4-2-21、已知公式如下: ?x?f(x)??x?5?8x2?32?(x?1)(1?x?10) (x?10)编写函数func完成上述公式的计算。【2015年】 float func(float x) { if(x<1) return x; else if ( ) return x+5; else ; } 4-2-22、编写函数,通过指针将一个字符串反向,如下程序的输出为:dcba。【2015年】 void strReverse(char *s) { char c; char *p; ; while(*p!='\\0') p++; ; while(s<=p) { c=*s; *s=*p; s++; *p=c; ; } } main() { char a[10]=\strReverse(a); printf(\} 4-2-23、学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。函 第 28 页 共 46 页 数creat()的功能是把结构体数组中的数据写入到二进制文件record.dat中。函数f()的功能是:把指定分数范围内的学生数据放在指针b所指的结构体中,分数范围内的学生人数由函数值返回。例如,输入的分数是60、69,则应当把分数在60~69的学生数据输出,包含60分和69分的学生数据。【2016年】 #include __________________ { char num[N]; int score; }SREC; int creat(SREC *std) { FILE *fp; int i; if((__________________)==NULL) return 0; printf(\for(i=0;i } /*creat()函数结束*/ int f(SREC *a,SREC *b,int l,int h); int main() { SREC s[N]={{\ {\ SREC h[N]; /*h用来存放满足分数条件范围内的学生人数*/ int i,n,low,heigh,t; /*n用来存放满足分数条件范围内的学生人数*/ int result; /*low、heigh分别用来存放分数范围内的下界和上界*/ result=creat(s); /*result表示文件写入操作是否成功*/ if(result) { printf(\printf(\if(heigh { t=heigh;heigh=low;low=t; } n=__________________; if(n==0) printf(\else { printf(\for(i=0;i printf(\printf(\} } else printf(\return 0; 第 29 页 共 46 页 } /*main()函数结束*/ int f(SREC *a,SREC *b,int l,int h) /*用来存放满足分数条件范围内的学生数据*/ { int i,j=0,n; for(i=0;i { if(a[i].score>=l && a[i].score<=h) { __________________ b[j].score=a[i].score; j++; } } return j; } 3、程序改错,不得增行或删行。 4-3-1、下面的程序是求 ?n!n?1m,在fun()函数中存在2处错误,请标记并改正。【2007年】 #include long fun(int x) { int m,n; long sum; for (m=1;m<=x;m++) { t=1; for(n=1;n<=m;n++) t=m*n; sum+=t; } return sum; } main() { int num; printf(\ printf(\??+%d!=%ld\\n\ } 4-3-2、下列程序的功能是:从字符串str中,删除所有字母'C',不区分大小写。如:输入字符串\,删除后的字符串为\。在main()函数中有2处错误,请标记并改正。【2007年】 #include { char str[80]; int i=0,j=0; printf(\请输入字符串:\ gets(str); while(str[i]!='\\0') { if(str[i]!='c'||str[i]!='C') str[j]=str[i]; i++; 第 30 页 共 46 页