欢迎来到天天文库
浏览记录
ID:5223740
大小:28.50 KB
页数:8页
时间:2017-12-06
《合肥工业大学c语言题库程序设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、合肥工业大学C语言题库程序设计第1题(10.0分)/*------------------------------------------------【程序设计】--------------------------------------------------功能:从键盘上输入任意实数,求出其所对应的函数值。z=e的x次幂(x>10)z=log(x+3)(x>-3)z=sin(x)/((cos(x)+4)------------------------------------------------*/#include2、h.h>#includedoubley(floatx){/**********Program**********//**********End**********/}main(){floatx;scanf("%f",&x);printf("y=%f",y(x));yzj();getch();}yzj(){FILE*IN,*OUT;intn;floati;doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFileError");}OUT=fopen3、("out.dat","w");if(OUT==NULL){printf("WriteFileError");}for(n=0;n<10;n++){fscanf(IN,"%f",&i);o=y(i);fprintf(OUT,"%ld",o);}fclose(IN);fclose(OUT);}答案:----------------------doublez;if(x>10)z=exp(x);elseif(x>-3)z=log(x+3);elsez=sin(x)/(cos(x)+4);return(z);------------4、----------第2题(10.0分)/*------------------------------------------------【程序设计】--------------------------------------------------功能:在键盘上输入一个3行3列矩阵的各个元素的值(值为整数),然后输出主对角线元素的积,并在fun()函数中输出。------------------------------------------------*/#include"stdio.h"voidmain(){inti,j5、,s,a[3][3];;for(i=0;i<3;i++){for(j=0;j<3;j++)scanf("%d",&a[i][j]);}s=fun(a);printf("Sum=%d",s);yzj();getch();}intfun(inta[3][3]){/**********Program**********//**********End**********/}yzj(){FILE*IN,*OUT;intm;intn;inti[3][3];into;IN=fopen("in.dat","r");if(IN==NULL){6、printf("ReadFileError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFileError");}for(m=0;m<3;m++){for(n=0;n<3;n++)fscanf(IN,"%d",&i[m][n]);}o=fun(i);{fprintf(OUT,"%d",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti,j;sum=1;for(i=0;7、i<3;i++)sum=sum*a[i][i];returnsum;----------------------第3题(10.0分)/*------------------------------------------------【程序设计】--------------------------------------------------功能:求1到100之间的偶数之积。------------------------------------------------*/#include"stdio.h"doublefun(i8、ntm){/**********Program**********//**********End**********/}voidmain(){printf("ji=%f",fun(100));yzj();getch();}yzj(){FILE*IN,*OUT
2、h.h>#includedoubley(floatx){/**********Program**********//**********End**********/}main(){floatx;scanf("%f",&x);printf("y=%f",y(x));yzj();getch();}yzj(){FILE*IN,*OUT;intn;floati;doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFileError");}OUT=fopen
3、("out.dat","w");if(OUT==NULL){printf("WriteFileError");}for(n=0;n<10;n++){fscanf(IN,"%f",&i);o=y(i);fprintf(OUT,"%ld",o);}fclose(IN);fclose(OUT);}答案:----------------------doublez;if(x>10)z=exp(x);elseif(x>-3)z=log(x+3);elsez=sin(x)/(cos(x)+4);return(z);------------
4、----------第2题(10.0分)/*------------------------------------------------【程序设计】--------------------------------------------------功能:在键盘上输入一个3行3列矩阵的各个元素的值(值为整数),然后输出主对角线元素的积,并在fun()函数中输出。------------------------------------------------*/#include"stdio.h"voidmain(){inti,j
5、,s,a[3][3];;for(i=0;i<3;i++){for(j=0;j<3;j++)scanf("%d",&a[i][j]);}s=fun(a);printf("Sum=%d",s);yzj();getch();}intfun(inta[3][3]){/**********Program**********//**********End**********/}yzj(){FILE*IN,*OUT;intm;intn;inti[3][3];into;IN=fopen("in.dat","r");if(IN==NULL){
6、printf("ReadFileError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFileError");}for(m=0;m<3;m++){for(n=0;n<3;n++)fscanf(IN,"%d",&i[m][n]);}o=fun(i);{fprintf(OUT,"%d",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti,j;sum=1;for(i=0;
7、i<3;i++)sum=sum*a[i][i];returnsum;----------------------第3题(10.0分)/*------------------------------------------------【程序设计】--------------------------------------------------功能:求1到100之间的偶数之积。------------------------------------------------*/#include"stdio.h"doublefun(i
8、ntm){/**********Program**********//**********End**********/}voidmain(){printf("ji=%f",fun(100));yzj();getch();}yzj(){FILE*IN,*OUT
此文档下载收益归作者所有