欢迎来到天天文库
浏览记录
ID:41686814
大小:1.65 MB
页数:116页
时间:2019-08-30
《二级C语言题库答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第1套题一、程序填空题#include#include#defineN5typedefstruct{intnum;charname[10];chartel[10];}STYPE;voidcheck();/**********found**********/intfun(STYPE*std){/**********found**********/FILE*fp;inti;if((fp=fopen("myfile5.dat","wb"))==NULL)return(0);printf("Output
2、datatofile!");for(i=0;i#includevoidfun(char*s,char*t){inti,sl;sl=strlen(s);/************found************/for(i=0;i<=sl;i++)t[i]=s[i];for(i=0;i3、l;i++)t[sl+i]=s[sl-i-1];/************found************/t[sl+sl]=' ';}main(){chars[100],t[100];printf("Pleaseenterstrings:");scanf("%s",s);fun(s,t);printf("Theresultis:%s",t);}第2套题一、程序填空题#include#include#includevoidWriteText(FILE*);voidRe4、adText(FILE*);main(){FILE*fp;if((fp=fopen("myfile4.txt","w"))==NULL){printf("openfail!!");exit(0);}WriteText(fp);fclose(fp);if((fp=fopen("myfile4.txt","r"))==NULL){printf("openfail!!");exit(0);}ReadText(fp);fclose(fp);}/**********found**********/voidWriteText(FILE*fw5、){charstr[81];printf("Enterstringwith-1toend:");gets(str);while(strcmp(str,"-1")!=0){/**********found**********/fputs(str,fw);fputs("",fw);gets(str);}}voidReadText(FILE*fr){charstr[81];printf("Readfileandoutputtoscreen:");fgets(str,81,fr);while(!feof(fr)){/****6、******found**********/printf("%s",str);fgets(str,81,fr);}}二、程序改错题#include/************found************/voidfun(longs,long*t){longsl=10;*t=s%10;while(s>0){s=s/100;*t=s%10*sl+*t;/************found************/sl=sl*10;}}main(){longs,t;printf("Pleaseenters:");sc7、anf("%ld",&s);fun(s,&t);printf("Theresultis:%ld",t);}第3套题一、程序填空题#include#includeintfun(char*fname){FILE*fp;inti,n;floatx;if((fp=fopen(fname,"w"))==NULL)return0;for(i=1;i<=10;i++)/**********found**********/fprintf(fp,"%d%f",i,sqrt((double)i));printf("8、Succeed!!");/**********found**********/Fclose(fp);printf("Thedatainfile:");/**********found****
3、l;i++)t[sl+i]=s[sl-i-1];/************found************/t[sl+sl]=' ';}main(){chars[100],t[100];printf("Pleaseenterstrings:");scanf("%s",s);fun(s,t);printf("Theresultis:%s",t);}第2套题一、程序填空题#include#include#includevoidWriteText(FILE*);voidRe
4、adText(FILE*);main(){FILE*fp;if((fp=fopen("myfile4.txt","w"))==NULL){printf("openfail!!");exit(0);}WriteText(fp);fclose(fp);if((fp=fopen("myfile4.txt","r"))==NULL){printf("openfail!!");exit(0);}ReadText(fp);fclose(fp);}/**********found**********/voidWriteText(FILE*fw
5、){charstr[81];printf("Enterstringwith-1toend:");gets(str);while(strcmp(str,"-1")!=0){/**********found**********/fputs(str,fw);fputs("",fw);gets(str);}}voidReadText(FILE*fr){charstr[81];printf("Readfileandoutputtoscreen:");fgets(str,81,fr);while(!feof(fr)){/****
6、******found**********/printf("%s",str);fgets(str,81,fr);}}二、程序改错题#include/************found************/voidfun(longs,long*t){longsl=10;*t=s%10;while(s>0){s=s/100;*t=s%10*sl+*t;/************found************/sl=sl*10;}}main(){longs,t;printf("Pleaseenters:");sc
7、anf("%ld",&s);fun(s,&t);printf("Theresultis:%ld",t);}第3套题一、程序填空题#include#includeintfun(char*fname){FILE*fp;inti,n;floatx;if((fp=fopen(fname,"w"))==NULL)return0;for(i=1;i<=10;i++)/**********found**********/fprintf(fp,"%d%f",i,sqrt((double)i));printf("
8、Succeed!!");/**********found**********/Fclose(fp);printf("Thedatainfile:");/**********found****
此文档下载收益归作者所有