资源描述:
《《程序设计题练习》PPT课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、【程序设计1】:功能:求1到100之间的偶数之积[3]。1:#include2:voidwwjt();3:doublefun(intm)4:{/********Program**********/5:6:7:/********End**********/}8:9:Main()10:{printf(“ji=%f”,fun(100));11:wwjt();}1voidwwjt();{FILE*IN,*OUT;IntiIN,i;doubledOUT;IN=fopen(“in.dat”,”r”);if(IN==NULL){printf
2、(“PleaseVerifyTheCurrerntDir..itMayBeChanged”);}OUT=fopen(“out.dat”,”w”);if(OUT==NULL){printf(“PleaseVerifyTheCurrerntDir..itMayBeChanged”);}2if(OUT==NULL){printf(“PleaseVerifyTheCurrerntDir..itMayBeChanged”);}for(i=0;i<5;i++){fscan(IN,”%d”,&iIN);dOUT=fun(iIN);fprintf(OUT,”%f
3、n”,dOUT);}fclose(IN);fclose(OUT);}3【程序设计1】:功能:求1到100之间的偶数之积[3]。答案:doubley=1;inti;for(i=1;i<=n;i++)if(i%2==0)y*=i;returny;4【程序设计2】:用while语句求1~100的累计和(377)。1:#include2:voidwwjt();3:intfun(intn)4:{/**********Program**********/5:6:7:8:/**********End**********/}9:voidmain(
4、):10:{intsum=0;11:sum=fun(100);12:printf(“sum=%d”,sum);13:wwjt();}5voidwwjt(){FILE*IN,*OUT;inti;intiIN,iOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itM
5、ayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%d",iOUT);}fclose(IN);fclose(OUT);}6【程序设计2】:用while语句求1~100的累计和。答案:intsum=0,i=0;while(i<=n){sum=sum+i;i++;}returnsum;7【程序设计3】编写函数求3!+6!+9!+12!+15+18!+21!。1:#include2:voidwwjt();3:floatsum
6、(intn)4:{/**********Program**********/5:6:7:8:/**********End**********/}9:main()10:{11:printf("thissum=%e",sum(21));12:wwjt();}8voidwwjt(){FILE*IN,*OUT;inti;intiIN,iOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.d
7、at","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%d",iOUT);}fclose(IN);fclose(OUT);}9【程序设计3】:功能:编写函数求3!+6!+9!+12!+15!+18!+21!。答案:inti,j;floatt,s=0;for(i=3;i<=n;i=i+3){t=1;for(j=1;j<=i
8、;j++)t=t*j;s=s+t;}returns;10【程序设计4】功能:求一个给定字符串中的字母的个数。1:#incl