资源描述:
《C语言模拟题库16》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*------------------------------------------------【程序设计】--------------------------------------------------功能:求k!(k〈13),所求阶乘的值作为函数值返回。(要求使用递归)------------------------------------------------*/#include#include"conio.h"voidbky();longfun(intk){/**********Begin*********
2、*//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("Theresultis%ld",fun(m));bky();}voidbky(){FILE*IN,*OUT;ints;intt;longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEEr
3、ror");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%ld",o);}fclose(IN);fclose(OUT);}【参考代码】if(k>0)return(k*fun(k-1));elseif(k==0)return1L;===============【考生代码】/*------------------------------------------------【程序设计】-------------------------------------------
4、-------功能:求1到w之间的奇数之和。(w是大于等于100小于等于1000的整数)------------------------------------------------*/#include#include"conio.h"voidbky();longfun(intw){/**********Begin**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("Theresultis%ld
5、",fun(m));bky();}voidbky(){FILE*IN,*OUT;intc;intt;longo;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,"%d",&t);o=fun(t);fprintf(OUT,"%ld",o);}fclose(IN);fclose(OU
6、T);}【参考代码】longy=0;inti;for(i=1;i<=w;i++)if(i%2==1)y+=i;returny;===============【考生代码】/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一批数中最大值和最小值的差。------------------------------------------------*/#defineN30#inclu
7、de"stdlib.h"#includevoidbky();intmax_min(inta[],intn){/**********Begin**********//**********End**********/}main(){inta[N],i,k;for(i=0;i8、,k);bky();}voidbky(){FILE*IN,*OUT;intn;inti[30];into;IN=fopen("in.dat","r");if(IN=