资源描述:
《C语言模拟题库5》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1【程序设计】--------------------------------------------------功能:判断一个整数w的各位数字平方之和能否被5整除,可以被5整除则返回1,否则返回0。------------------------------------------------*/#include#include"conio.h"voidbky();intfun(intw){/**********Begin**********//**********End**********/}main(){int
2、m;printf("Enterm:");scanf("%d",&m);printf("Theresultis%d",fun(m));bky();}voidbky(){FILE*IN,*OUT;intc;intt;into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(c=1;c<=5;c++){fscanf(IN,"
3、%d",&t);o=fun(t);fprintf(OUT,"%d",o);}fclose(IN);fclose(OUT);【参考代码】intk,s=0;do{s=s+(w%10)*(w%10);w=w/10;}while(w!=0);if(s%5==0)k=1;elsek=0;return(k);===============2/*------------------------------------------------【程序设计】-----------------------------------------------
4、---功能:用函数实现字符串的复制,不允许用strcpy()函数。------------------------------------------------*/#includevoidbky();voidcopy(charstr1[],charstr2[]){/**********Begin**********//**********End**********/}main(){voidcopy();charc1[40],c2[40];gets(c1);copy(c1,c2);puts(c2);bky();}vo
5、idbky(){FILE*IN,*OUT;chari[100];charo[100];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);copy(i,o);fprintf(OUT,"%s",o);fclose(IN);fclose(OUT);}【参考代码】inti;for(i=0;str1[i]!
6、=' ';i++)str2[i]=str1[i];str2[i]=' ';===============【考生代码】3/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写函数fun将一个由四个数字组成的字符串转换为每两个数字间有一个空格的形式输出。例如:输入“4567”,应输出“4□5□6□7”(□表示空格)。---------------------------
7、---------------------*/#includevoidbky();fun(chars[]){/**********Begin**********//**********End**********/}main(){staticcharstr[80];printf("输入含有四个数字的字符串:");scanf("%s",str);fun(str);printf("结果是:%s",str);bky();}voidbky(){FILE*IN,*OUT;intn;inti[200];into;IN=fo
8、pen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFI