| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- 程序设计题(一)
- 请编写函数fun,它的功能是计算下列级数和,和值由函数值返回。
- S=1+x+x^2/2!+x^3/3!+…+x^n/n!
- 例如,当n=10,x=0.3时,函数值为1.349859。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include<conio.h>
- #include<stdio.h>
- #include<math.h>
- #include<stdlib.h>
- double fun(double x, int n)
- {
-
- }
- void main()
- {
- FILE *wf;
- system("CLS");
- printf("%f ",fun(0.3,10));
- /******************************/
- wf=fopen("out.dat","w");
- fprintf(wf,"%f",fun(0.3,10));
- fclose(wf);
- /*****************************/
- }
- 程序设计题(二)
- 编写函数fun,其功能是:求出1~1000之间能被7或11整除,但不能同时被7和11整除的所有整数,并将其放在a所指的数组中,通过n返回这些数的个数。
- 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <stdio.h>
- void fun (int *a, int *n)
- {
- }
- main( )
- { int aa[1000], n, k ;
- void NONO ( );
- fun ( aa, &n ) ;
- for ( k = 0 ; k < n ; k++ )
- if((k + 1) % 10 == 0) printf("\n") ;
- else printf("%5d", aa[k]) ;
- NONO( );
- }
- void NONO ( )
- {/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
- int aa[1000], n, k ;
- FILE *fp ;
- fp = fopen("out.dat","w") ;
- fun ( aa, &n ) ;
- for ( k = 0 ; k < n ; k++ )
- if((k + 1) % 10 == 0) fprintf(fp, "\n") ;
- else fprintf(fp, "%5d", aa[k]) ;
- fclose(fp) ;
- }
- 程序设计题(三)
- 请编写函数fun,该函数的功能是:将s所指字符串中ASCII码值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
- 例如,若s所指字符串中的内容为"ABCDEFG12345",其中字符B的ASCII码值为偶数,字符2的ASCII码值为偶数,都应当删除,其他依此类推。最后t所指的数组中的内容应是"ACEG135"。
- 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
- #include<stdio.h>
- #include<string.h>
- #include<conio.h>
- #include<stdlib.h>
- void fun(char *s, char t[])
- {
-
- }
- void main()
- {
- FILE *wf;
- char s[100],t[100];
- system("CLS");
- printf("\nPlease enter string S: ");
- scanf("%s",s);
- fun(s,t);
- printf("\nThe result is :%s\n",t);
- /******************************/
- wf=fopen("out.dat","w");
- fun("ABCDEFG12345",t);
- fprintf(wf,"%s",t);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(四)
- 请编写函数void fun (int x, int pp[], int *n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
- 例如,若x中的值为30,则有4个数符合要求,它们是1、3、5、15。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- void fun (int x, int pp[], int *n)
- {
-
- }
- void main ()
- {
- FILE *wf;
- int x,aa[1000], n, i ;
- system("CLS");
- printf("\nPlease enter an integer number : \n ") ;
- scanf ("%d", &x) ;
- fun (x, aa, &n) ;
- for (i=0 ; i<n ; i++)
- printf ("%d ", aa [i]);
- printf ("\n ") ;
- /******************************/
- wf=fopen("out.dat","w");
- fun (30, aa, &n) ;
- for (i=0 ; i<n ; i++)
- fprintf (wf,"%d ", aa [i]);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(五)
- 请编函数fun,其功能是将一个数字字符串转换成与其面值相同的长整型整数。可调用strlen函数求字符串的长度。例如:在键盘输入字符串2345210,函数返回长整型数2345210。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun指定的部位填入所编写的若干语句。
- #include <stdio.h>
- #include <string.h>
- void NONO();
- long fun( char *s )
- {
- }
- main()
- { char s[10]; long r;
- printf("请输入一个长度不超过9个字符的数字字符串 : "); gets(s);
- r = fun( s );
- printf(" r = %ld\n" , r );
- NONO();
- }
- void NONO()
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- FILE *fp, *wf ;
- int i; long r;
- char s[10], *p;
- fp = fopen("in.dat","r") ;
- wf = fopen("out.dat","w") ;
- for(i = 0 ; i < 10 ; i++) {
- fgets(s, 10, fp);
- p = strchr(s, '\n');
- if(p) *p = 0;
- r = fun(s);
- fprintf(wf, "%ld\n", r);
- }
- fclose(fp) ;
- fclose(wf) ;
- }
- 程序设计题(六)
- 假定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:除了尾部的*号之外,将字符中的其它的*号全部删除。形参p已指向字符串中最后的一个字母。在编写函数时,不得使用C语言提供的字符串函数。
- 例如,字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容应当是ABCDEFG*******。
- 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <stdio.h>
- void fun( char *a, char *p )
- {
- }
- main()
- { char s[81],*t;
- void NONO ( );
- printf("Enter a string:\n");gets(s);
- t=s;
- while(*t)t++;
- t--;
- while(*t=='*')t--;
- fun( s , t );
- printf("The string after deleted:\n");puts(s);
- NONO();
- }
- void NONO()
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- FILE *in, *out ;
- int i ; char s[81],*t ;
- in = fopen("in.dat","r") ;
- out = fopen("out.dat","w") ;
- for(i = 0 ; i < 10 ; i++) {
- fscanf(in, "%s", s) ;
- t=s;
- while(*t)t++;
- t--;
- while(*t=='*')t--;
- fun(s,t) ;
- fprintf(out, "%s\n", s) ;
- }
- fclose(in) ;
- fclose(out) ;
- }
- 程序设计题(七)
- 编写函数void fun(char *tt,int pp[]),统计在tt所指的字符串中'a'到'z'26个小写字母各自出现的次数,并依次放在pp所指的数组中。
- 例如,当输入字符串abcdefgabcdeabc后,程序的输出结果应该是:
- 3 3 3 2 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <stdio.h>
- #include <string.h>
- void fun(char *tt, int pp[])
- {
- }
- main( )
- { char aa[1000] ;
- int bb[26], k ;
- void NONO ( );
- printf( "\nPlease enter a char string:" ) ; scanf("%s", aa) ;
- fun(aa, bb ) ;
- for ( k = 0 ; k < 26 ; k++ ) printf ("%d ", bb[k]) ;
- printf( "\n" ) ;
- NONO ( ) ;
- }
- void NONO ( )
- {/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
- char aa[1000] ;
- int bb[26], k, i ;
- FILE *rf, *wf ;
- rf = fopen("in.dat","r") ;
- wf = fopen("out.dat","w") ;
- for(i = 0 ; i < 10 ; i++) {
- fscanf(rf, "%s", aa) ;
- fun(aa, bb) ;
- for ( k = 0 ; k < 26 ; k++ ) fprintf (wf, "%d ", bb[k]) ;
- fprintf(wf, "\n" ) ;
- }
- fclose(rf) ;
- fclose(wf) ;
- }
- 程序设计题(八)
- 下列程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N]),该函数的功能是:将数组左下半三角元素中的值全部置成0。例如a数组中的值为:
- 1 9 7
- 2 3 8
- 4 5 6
- 则返回主程序后a数组中的值应为:
- 0 9 7
- 0 0 8
- 0 0 0
- 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define N 5
- void fun (int a[][N])
- {
-
- }
- void main()
- {
- FILE *wf;
- int a[N][N],i,j;
- int b[N][N]={1,9,7,2,4,2,3,8,1,2,4,5,6,7,5,4,0,6,8,0,2,7,1,6,4};
- system("CLS");
- printf("*****The array*****\n");
- for(i=0;i<N;i++) /*产生一个随机的5*5矩阵*/
- { for(j=0;j<N;j++)
- {a[i][j]=rand()%10;
- printf("%4d", a[i][j]);
- }
- printf("\n");
- }
- fun(a);
- printf("THE RESULT\n");
- for(i=0;i<N;i++)
- { for(j=0;j<N;j++)
- printf("%4d",a[i][j]);
- printf("\n");
- }
- /******************************/
- wf=fopen("out.dat","w");
- fun(b);
- for(i=0;i<N;i++)
- { for(j=0;j<N;j++)
- fprintf(wf,"%4d",b[i][j]);
- fprintf(wf,"\n");
- }
- fclose(wf);
- /*****************************/
- }
- 程序设计题(九)
- 请编写函数fun,该函数的功能是:删除一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
- 例如,若一维数组中的数据是:
- 2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
- 删除后,数组中的内容应该是:
- 2 3 4 5 6 7 8 9 10。
- 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
- #include <stdio.h>
- #define N 80
- int fun(int a[], int n)
- {
-
- }
- void main()
- {
- FILE *wf;
- int a[N]={ 2,2,2,3,4,4,5,6,6,6,6,7,7,8,9,9,10,10,10,10}, i, n=20;
- printf("The original data :\n");
- for(i=0; i<n; i++)
- printf("%3d",a[i]);
- n=fun(a,n);
- printf("\nThe data after deleted :\n");
- for(i=0; i<n; i++)
- printf("%3d",a[i]);
- printf("\n");
- /******************************/
- wf=fopen("out.dat","w");
- for(i=0; i<n; i++)
- fprintf(wf,"%3d",a[i]);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(十)
- 函数fun的功能是:将s所指字符串中除下标为偶数同时ASCII码值也为偶数的字符外,其余的全部删除;字符串中剩余字符所形成的新串放在t所指的数组中。
- 例如,若s所指字符串中的内容为"ABCDEFG123456",其中字符A的ASCII码值为奇数,因此应当删除;字符B的ASCII码值为偶数,但在数组中的下标为奇数,因此也应当删除;字符2的ASCII码值为偶数,在数组中的下标也为偶数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是"246"。
- 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <stdio.h>
- #include <string.h>
- void fun(char *s, char t[])
- {
- }
- main()
- {
- char s[100], t[100];
- void NONO ( );
- printf("\nPlease enter string S:"); scanf("%s", s);
- fun(s, t);
- printf("\nThe result is: %s\n", t);
- NONO();
- }
- void NONO ( )
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- char s[100], t[100] ;
- FILE *rf, *wf ;
- int i ;
- rf = fopen("in.dat","r") ;
- wf = fopen("out.dat","w") ;
- for(i = 0 ; i < 10 ; i++) {
- fscanf(rf, "%s", s) ;
- fun(s, t) ;
- fprintf(wf, "%s\n", t) ;
- }
- fclose(rf) ;
- fclose(wf) ;
- }
- 程序设计题(十一)
- 请编写函数fun,其功能是:找出2×M整型二维数组中最大元素的值,并将此值返回调用函数。
- 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include <stdio.h>
- #define M 4
- int fun (int a[][M])
- {
- }
- main( )
- { int arr[2][M]={5,8,3,45,76,-4,12,82} ;void NONO ();
- printf("max =%d\n", fun(arr)) ;
- NONO( ) ;
- }
- void NONO ()
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- FILE *wf ;
- int arr[][M]={5,8,3,90,76,-4,12,82} ;
- wf = fopen("out.dat","w") ;
- fprintf(wf, "max=%d\n", fun(arr)) ;
- fclose(wf) ;
- }
- 程序设计题(十二)
- 请编写一个函数fun,它的功能是:将ss所指字符串中所有下标为奇数位置的字母转换为大写(若该位置上不是字母,则不转换)。
- 例如,若输入"abc4Efg",则应输出"aBc4EFg"。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include<conio.h>
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- void fun(char *ss)
- {
-
-
- }
- void main()
- {
- FILE *wf;
- char tt[81],s[81]="abc4Efg";
- system("CLS");
- printf("\nPlease enter an string within 80 characters:\n");
- gets(tt);
- printf("\nAfter changing, the string\n %s",tt);
- fun(tt);
- printf("\nbecomes\n %s\n",tt);
- /******************************/
- wf=fopen("out.dat","w");
- fun(s);
- fprintf (wf,"%s",s);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(十三)
- 请编写函数fun,该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。
- 例如,若二维数组中的数据为
- W W W W
- S S S S
- H H H H
- 则字符串中的内容应是:WSHWSHWSHWSH。
- 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
- #include<stdio.h>
- #define M 3
- #define N 4
- void fun(char (*s)[N],char *b)
- {
-
-
- }
- void main()
- {
- FILE *wf;
- char a[100],w[M][N]={{ 'W', 'W', 'W', 'W'},{'S', 'S', 'S', 'S'},{'H', 'H', 'H', 'H'}};
- int i,j;
- printf("The matrix:\n");
- for(i=0;i<M;i++)
- { for(j=0;j<N;j++)
- printf("%3c",w[i][j]);
- printf("\n");
- }
- fun(w,a);
- printf("The A string:\n");
- puts(a);
- printf("\n ");
- /******************************/
- wf=fopen("out.dat","w");
- fprintf(wf,"%s",a);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(十四)
- 已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- #include<stdio.h>
- #include<string.h>
- #include<conio.h>
- #include<stdlib.h>
- #define N 10
- typedef struct ss /*定义结构体*/
- { char num[10];
- int s;
- } STU;
- fun(STU a[], STU *s)
- {
-
- }
- void main()
- {
- FILE *wf;
- STU a[N]={{ "A01",81},{ "A02",89},{ "A03",66},{ "A04",87},{ "A05",77},
- { "A06",90},{ "A07",79},{ "A08",61},{ "A09",80},{ "A10",71}},m;
- int i;
- system("CLS");
- printf("*****The original data*****");
- for(i=0;i<N;i++)
- printf("No=%s Mark=%d\n", a[i].num,a[i].s);
- fun(a,&m);
- printf("*****THE RESULT*****\n");
- printf("The top :%s, %d\n",m.num,m.s);
- /******************************/
- wf=fopen("out.dat","w");
- fprintf(wf,"%s,%d",m.num,m.s);
- fclose(wf);
- /*****************************/
- }
- 程序设计题(十五)
- 请编写函数fun,其功能是:判断形参n中的正整数是几位数(输入数据的位数不超过4位),并将结果通过函数值返回。例如:若输入的数据为 123,则输出结果为:输入的数字是3位。
- 注意:请勿改动主函数main和其他函数中的任何
- 内容,仅在函数fun的花括号中填入所编写的若干语句。
- #include <stdio.h>
- void NONO();
- int fun(int n)
- {
- }
- main()
- { int n, place ;
- do{
- printf("请输入一个4位以内的正整数: ");
- scanf("%d", &n);
- } while (n<0 || n>9999);
- place = fun(n);
- printf( "输入的数字是%d位\n", place );
- NONO();
- }
- void NONO()
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- FILE *fp, *wf ;
- int i, n, place ;
- fp = fopen("in.dat","r") ;
- wf = fopen("out.dat","w") ;
- for( i=0; i<10; i++ )
- {
- fscanf(fp,"%d ", &n);
- place = fun(n);
- fprintf(wf, "%d\n", place);
- }
- fclose(fp) ;
- fclose(wf) ;
- }
- 程序设计题(十六)
- 请编写函数fun,其功能是:计算并输出3~n之间所有素数的平方根之和。
- 例如,若主函数从键盘给n输入100后,则输出为sum=148.874270。
- 注意:n的值要大于2但不大于100。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- 试题程序:
- #include <stdio.h>
- #include <math.h>
- double fun(int n)
- {
- }
- main()
- {
- int n;
- double sum;
- FILE *out;
- printf("Input n=");
- scanf("%d",&n);
- sum=fun(n);
- printf("\nsum=%f\n",sum);
- /******************************/
- out=fopen("out.dat","w");
- fprintf(out,"%f\n",fun(180));
- fclose(out);
- /******************************/
- }
- 程序设计题(十七)
- 编写函数fun,其功能是:将两个两位数的正整数a、b合并成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。
- 例如,当a=45,b=12时,调用该函数后,c=5142。
- 注意:数据文件IN.DAT中的数据不得修改。
- 试题程序:
- #include <stdio.h>
- void fun(int a,int b,long *c)
- {
- }
- main()
- { int a,b; long c;
- void NONO( );
- printf("Input a, b:");
- scanf("%d%d", &a, &b);
- fun(a,b,&c);
- printf("The result is: %d\n", c);
- NONO();
- }
- void NONO( )
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
- FILE *rf, *wf ;
- int i, a,b ; long c ;
- rf=fopen("in.dat", "r");
- wf=fopen("out.dat","w");
- for(i=0;i<10;i++)
- {
- fscanf(rf, "%d,%d",&a,&b);
- fun(a, b, &c) ;
- fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c);
- }
- fclose(rf);
- fclose(wf);
- }
- 程序设计题(十八)
- 请编写函数fun,该函数的功能是:判断字符串是否为回文,若是,则函数返回1,主函数中输出"YES",否则返回0,主函数中输出"NO"。回文是指顺读和倒读都一样的字符串。
- 例如,字符串LEVEL是回文,而字符串123312就不是回文。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- 试题程序:
- #include <stdio.h>
- #define N 80
- int fun(char *str)
- {
- }
- main()
- {
- char s[N];
- FILE *out;
- char *test[]={"1234321","123421","123321","abcdCBA"};
- int i;
- printf("Enter a string : ");
- gets(s);
- printf("\n");
- puts(s);
- if(fun(s))
- printf("YES\n");
- else
- printf("NO\n");
- /************************************/
- out=fopen("out.dat","w");
- for(i=0;i<4;i++)
- if(fun(test[i]))
- fprintf(out,"YES\n");
- else
- fprintf(out,"NO\n");
- fclose(out);
- /************************************/
- }
- 程序设计题(十九)
- 请编写函数fun,对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII码降序排列。例如,原来的字符串为"CEAedca",排序后输出为"CedcEAa"。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
- 试题程序:
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- void fun(char *s,int num)
- {
- }
- main()
- {
- void NONO( );
- char s[10];
- printf("输入7个字符的字符串:");
- gets(s);
- fun(s,7);
- printf("\n%s",s);
- NONO();
- }
- void NONO()
- {
- /* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
- 输出数据,关闭文件。 */
- char s[10] ;
- FILE *rf, *wf ;
- int i = 0 ;
- rf=fopen("in.dat","r") ;
- wf=fopen("out.dat","w") ;
- while(i<10)
- {
- fgets(s,10,rf) ;
- s[7] = 0 ;
- fun(s,7);
- fprintf(wf, "%s\n", s) ;
- i++ ;
- }
- fclose(rf) ;
- fclose(wf) ;
- }
- 程序设计题(二十)
- 请编写函数fun,其功能是:将一组得分中,去掉一个最高分和一个最低分,然后求平均值,并通过函数返回。函数形参a指向存放得分的数组,形参n中存放得分个数(n>2)。
- 例如,若输入9.9 8.5 7.6 8.5 9.3 9.5 8.9 7.8 8.6 8.4十个得分,则输出结果为:8.687500。
- 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
- 试题程序:
- #include <stdio.h>
- void NONO();
- double fun(double a[ ],int n)
- {
- }
- main()
- { double b[10], r; int i;
- printf("输入10个数放入b数组中 : ");
- for (i=0; i<10; i++)
- scanf("%lf",&b[i]);
- printf("输入的10个数是 : ");
- for (i=0; i<10; i++)
- printf("%4.1lf ",b[i]);
- printf("\n");
- r=fun(b,10);
- printf("去掉最高分和最低分后的平均分 : %f\n", r );
- NONO();
- }
- void NONO()
- {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
- FILE *fp, *wf;
- int i, j ;
- double b[10], r;
- fp = fopen("in.dat","r");
- wf = fopen("out.dat","w");
- for(i = 0 ; i < 10 ; i++)
- {
- for(j = 0 ; j < 10 ; j++)
- {
- fscanf(fp,"%lf ",&b[j]);
- }
- r = fun(b, 10);
- fprintf(wf, "%f\n", r);
- }
- fclose(fp);
- fclose(wf);
- }
|