正在加载图片...
eatc.cn4月上机考试题库编程 main() 8、假定输入的字符串中只包含字母和*号。请编写函数fun i double x; 它的功能是除了字符串前导的*号之外将串中其它*号全部 rinf("Input eps: " 删除。在编写函数时,不得使用C语言提供的字符串函数 canf("%lf", &x); printf("neps =%f, Pl=%lfn,X, fun(x)); 例如,字符串中的内容为:***ABC*DEFG事*, NONOO 删除后,字符串中的内容应当是:·* ABCDEFG。 注意:部分源程序在文件PROG1C文件中 NONOO 清勿改动主函数main和其它函数中的任何内容,仅在 陳*本函数用于打开文件,输入数据,调用函数,输出数据,函数fun的花括号中填入你编写的若干语句 关闭文件。 #include <stdio h FILE*fp, *wf void fun( char *a) /以下代码仅供参考*/ fp= fopen("c: ltest\lin dat"," r") int FO.k: wf=fopen("c: \testlout dat", w") while(al=*)计++ for(i=0;i<10;计++){ k=H+1; fscanf(fp, "%lf",&x whle(a=0)/*以下程序段实现非*字符前移*/ fprintf(wf, %lf\n", fun(x)) fclose(wf) a[i+1w0; 7、m个人的成绩存放在 score数组中,请编写函数fun,它 的功能是将低于平均分的人数作为函数值返回,将低于平 mainO 均分的分数放在 below所指的数组中 i char s[81: 例如,当 score数组中的数据为:10、20、30、40、50 printf("Enter a string: \n") gets(s); 60、70、80、90时,函数返回的人数应该是4,beow中的 fun(s ) 数据应为:10、20、30、40 rinf("The string after deleted: \n"), puts(s); 注意:部分源程序在文件PROG1C文件中。 请勿改动主函数main和其它函数中的任何内容,仅在} 函数fun的花括号中填入你编写的若干语句 NONOO #include <stdio. h> /*本函数用于打开文件,输入数据,调用函数,输出数据 #include <string. h> 关闭文件 int fun( int score[, int m, int below D FILE *in,°out int i; char s81] in= fopen("c: testllin dat","r"), ut=fopen("c: testour. dat",w") for(=0;1<10,计+){ scanf(in, "%s"s) i int i, n, below[9] printf("bElow the average score are: " ) for(i=0; i<n; 1++) printf("%d", below) NONOO 9、假定输入的字符串中只包含字母和*号。请编写函数fun 它的功能是:将字符串中的前导*号全部移到字符串的尾部 NONO 例如,字符串中的内容为:事事率A*BC*DEFG*率 本函数用于打开文件,输入测试数据,调用fun函数 移 输出数据,关闭文件。* A*BC*DEF*G******。在编写函数时,不得使用C语 int i,j, n, below[10], score[10] 言提供的字符串函数。 FILE 主意:部分源程序在文件PROG1C文件中 fopen("c: ltest\lin dat","r) 清勿改动主函数main和其它函数中的任何内容,仅在 wf=fopen("c: \\test\lout. dat","w"); 函数fun的花括号中填入你编写的若干语句 #include <stdio h> for(=0; j<10; j++)fscanf(rf, "%d", &score D void fun( char a) n= fun(score, 10, below) for(j=0; j<n; j++)fprintf(wf, "%d", belowID 以下代码仅供参考* narp, "q int n=o fclose(rf) fclose( wf) Whle(·p==*)/统计串头个数n*宏为世纪教育 www.greatc.cn 4 月上机考试题库 编程题 3 } main( ) { double x; printf("Input eps:") ; scanf("%lf",&x); printf("\neps = %lf, PI=%lf\n", x, fun(x)); NONO(); } NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据, 关闭文件。 */ FILE *fp, *wf ; int i ; double x ; fp = fopen("c:\\test\\in.dat","r") ; wf = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%lf", &x) ; fprintf(wf, "%lf\n", fun(x)) ; } fclose(fp) ; fclose(wf) ; } 7、m 个人的成绩存放在 score 数组中,请编写函数 fun,它 的功能是:将低于平均分的人数作为函数值返回,将低于平 均分的分数放在 below 所指的数组中。 例如,当 score 数组中的数据为:10、20、30、40、50、 60、70、80、90 时,函数返回的人数应该是 4, below 中的 数据应为: 10、20、30、40。 注意: 部分源程序在文件 PROG1.C 文件中。 请勿改动主函数 main 和其它函数中的任何内容,仅在 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> #include <string.h> int fun(int score[], int m, int below[]) { } main( ) { int i, n, below[9] ; int score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90} ; n = fun(score, 9, below) ; printf( "\nBelow the average score are: " ) ; for (i = 0 ; i < n ; i++) printf("%d ", below[i]) ; NONO() ; } NONO ( ) {/* 本函数用于打开文件,输入测试数据,调用 fun 函数, 输出数据,关闭文件。*/ int i, j, n, below[10], score[10] ; FILE *rf, *wf ; rf = fopen("c:\\test\\in.dat","r") ; wf = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { for(j = 0 ; j < 10 ; j++) fscanf(rf, "%d", &score[j]) ; n = fun(score, 10, below) ; for(j = 0 ; j < n ; j++) fprintf(wf, "%d ", below[j]) ; fprintf(wf, "\n") ; } fclose(rf) ; fclose(wf) ; } 8、假定输入的字符串中只包含字母和*号。请编写函数 fun, 它的功能是:除了字符串前导的*号之外,将串中其它*号全部 删除。在编写函数时,不得使用 C 语言提供的字符串函数。 例如,字符串中的内容为:****A*BC*DEF*G*******, 删除后, 字符串中的内容应当是:****ABCDEFG。 注意: 部分源程序在文件 PROG1.C 文件中。 请勿改动主函数 main 和其它函数中的任何内容,仅在 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> void fun( char *a ) { /* 以下代码仅供参考 */ int i=0,k; while(a[i]=='*') i++; k=i+1; while(a[i]!='\0') /* 以下程序段实现非*字符前移 */ { } a[i+1]='\0'; } main() { char s[81]; printf("Enter a string:\n");gets(s); fun( s ); printf("The string after deleted:\n");puts(s); NONO(); } NONO() {/* 本函数用于打开文件,输入数据,调用函数,输出数据, 关闭文件。 */ FILE *in, *out ; int i ; char s[81] ; in = fopen("c:\\test\\in.dat","r") ; out = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(in, "%s", s) ; fun(s) ; fprintf(out, "%s\n", s) ; } fclose(in) ; fclose(out) ; } 9、假定输入的字符串中只包含字母和*号。请编写函数 fun, 它的功能是:将字符串中的前导*号全部移到字符串的尾部。 例如,字符串中的内容为:*******A*BC*DEF*G****, 移动后 , 字 符 串 中 的 内 容 应 当 是 : A*BC*DEF*G***********。在编写函数时, 不得使用 C 语 言提供的字符串函数。 注意: 部分源程序在文件 PROG1.C 文件中。 请勿改动主函数 main 和其它函数中的任何内容,仅在 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> void fun( char *a ) { /* 以下代码仅供参考 */ char *p,*q; int n=0; p=a; while(*p=='*') /* 统计串头'*'个数 n */
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有