正在加载图片...
宏为世纪教育www.greatc4月上机考试题库编程题 函数fun的花括号中填入你编写的若干语句。 for(=0,i<M,计+) #include <stdio h> i for(j=0 j<N; j++)printf( %6d, aa00); #define n 12 tf ("n"); typedef struct double S printf("nThe sum: %dn",y); double fun( STReC *a, StREC*b, int"n) ONOO: /*请在此函数内打开文件,输入测试数据,调用fun函 输出数据,关闭文件。 int i,j,y, k, aa[MIN; STREC S|N}={{"GA05",85},{"GA03",76} FIL LE rf *wf "GA02"69},{"GA04",85},{"GAo1",91} rf= fopen("c: test\in dat","r") "GA07",72},{"GA08",64},{"GA06",87} wf=fopen("c: \\test\out. dat","w") "GA09",60},{"GA11",79},{"GA12",73}, or(k=0,k<10;k++){ {"GA10",90}} 0;i<M;计++) STREC hN, t; FILE*out 0=0; j <N; j++)fscanf(rf, "%d",&aaOD int ij, n, double ave y= fun(aa ) ave=fun( s, h, &n ) fprintf(wf, "%d\",y); printf("The %d student data which is higher than %7.3f: n",n, ave) fclose(rf) for(F=0,<n,计++) printf("%s %4. 1fn,h[]. num, h( s); printf("n"); out= fopen("c: \testllout dat","w") 25、函数fun的功能是:将s所指字符串中除了下标为奇 fprintf(out, "%dln%7.3fun",n, ave) 数、同时ASCI值也为奇数的字符之外,其余的所有字符 for(i=0,<n-1;计++) 都删除串中剩余字符所形成的一个新串放在t所指的数组 i(hs<h]s){地血h,ht 例如,若s所指字符串中的内容为:" ABCDEFG12345° for(=0,i<n;计 其中字符A的ASCI码值虽为奇数,但所在元素的下标为 fprintf(out, %4.1f\n,h.S); 偶数,因此必需删除:而字符1的ASCI码值为奇数,所 fclose(out) 在数组中的下标也为奇数因此不应当删除,其它依此类推 最后t所指的数组中的内容应是:"135 注意:部分源程序存在文件PROG1C中。 24、请编写函数fun,函数的功能是求出二维数组周边元素 清勿改动主函数main和其它函数中的任何内容,仅在 之和,作为函数值返回。二维数组中的值在主函数中赋予。函数fun的花括号中填入你编写的若干语句 例如:二维数组中的值为 #include <stdio h> 3579 #include <string. h 29994 void fun(char *s, char tDD 69998 13570 则函数值为61 注意:部分源程序存在文件PROG1C文件中 请勿改动主函数main和其它函数中的任何内容,仅在 函数fun的花括号中填入你编写的若干语句 } #include <stdio h> maino #define M 4 #define n 5 har s[100, t] int fun( int aMIND) printf("nPlease enter string S: ) scanf("%s", s) printf("nThe result is: %s\n",t); NONOO NONO( nain() {*本函数用于打开文件,输入数据,调用函数,输出数据 int aa(M]N}={{1,3,5,7,9}, 关闭文件。 6,9,9,9,8} FILE·rf,wwf {1,3,5,7,0}; Int I rf= fopen("c: Itest\lin. dat","r") clrscrO wf=fopen("c: l\test\out. dat,"w") printf("The original data is: n"); for(i=0;i<10;计+)宏为世纪教育 www.greatc.cn 4 月上机考试题库 编程题 9 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> #define N 12 typedef struct { char num[10]; double s; } STREC; double fun( STREC *a, STREC *b, int *n ) { } main() { STREC s[N]={{"GA05",85},{"GA03",76}, {"GA02",69},{"GA04",85},{"GA01",91}, {"GA07",72},{"GA08",64},{"GA06",87}, {"GA09",60},{"GA11",79},{"GA12",73}, {"GA10",90}}; STREC h[N], t;FILE *out ; int i,j,n; double ave; ave=fun( s,h,&n ); printf("The %d student data which is higher than %7.3f:\n",n,ave); for(i=0;i<n; i++) printf("%s %4.1f\n",h[i].num,h[i].s); printf("\n"); out = fopen("c:\\test\\out.dat","w") ; fprintf(out, "%d\n%7.3f\n", n, ave); for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(h[i].s<h[j].s) {t=h[i] ;h[i]=h[j]; h[j]=t;} for(i=0;i<n; i++) fprintf(out,"%4.1f\n",h[i].s); fclose(out); } 24、请编写函数 fun,函数的功能是求出二维数组周边元素 之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为 61。 注意: 部分源程序存在文件 PROG1.C 文件中。 请勿改动主函数 main 和其它函数中的任何内容,仅在 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> #define M 4 #define N 5 int fun ( int a[M][N] ) { } main( ) { int aa[M][N]={{1,3,5,7,9}, {2,9,9,9,4}, {6,9,9,9,8}, {1,3,5,7,0}}; int i, j, y; clrscr(); printf ( "The original data is : \n" ); for ( i=0; i<M; i++ ) { for ( j =0; j<N; j++ ) printf( "%6d", aa[i][j] ); printf ("\n"); } y = fun ( aa ); printf( "\nThe sum: %d\n" , y ); printf("\n"); NONO( ); } NONO( ) {/* 请在此函数内打开文件,输入测试数据,调用 fun 函 数, 输出数据,关闭文件。 */ int i, j, y, k, aa[M][N] ; FILE *rf, *wf ; rf = fopen("c:\\test\\in.dat","r") ; wf = fopen("c:\\test\\out.dat","w") ; for(k = 0 ; k < 10 ; k++) { for(i = 0 ; i < M ; i++) for(j = 0 ; j < N ; j++) fscanf(rf, "%d", &aa[i][j]) ; y = fun ( aa ); fprintf(wf, "%d\n", y) ; } fclose(rf) ; fclose(wf) ; } 25、函数 fun 的功能是: 将 s 所指字符串中除了下标为奇 数、同时 ASCII 值也为奇数的字符之外,其余的所有字符 都删除,串中剩余字符所形成的一个新串放在 t 所指的数组 中。 例如,若 s 所指字符串中的内容为:"ABCDEFG12345", 其中字符 A 的 ASCII 码值虽为奇数,但所在元素的下标为 偶数,因此必需删除;而字符 1 的 ASCII 码值为奇数,所 在数组中的下标也为奇数,因此不应当删除,其它依此类推。 最后 t 所指的数组中的内容应是:"135"。 注意: 部分源程序存在文件 PROG1.C 中。 请勿改动主函数 main 和其它函数中的任何内容,仅在 函数 fun 的花括号中填入你编写的若干语句。 #include <stdio.h> #include <string.h> void fun(char *s, char t[]) { } main() { char s[100], t[100]; printf("\nPlease enter string S:"); scanf("%s", s); fun(s, t); printf("\nThe result is: %s\n", t); NONO(); } NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据, 关闭文件。 */ char s[100], t[100] ; FILE *rf, *wf ; int i ; rf = fopen("c:\\test\\in.dat","r") ; wf = fopen("c:\\test\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) {
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有