1、第 1 套题一、程序填空题#include #include #define N 5typedef struct int num;char name10;char tel10;STYPE;void check();/*found*/int fun(_1_ *std)/*found*/_2_ *fp; int i;if(fp=fopen(“myfile5.dat“,“wb“)=NULL)return(0);printf(“nOutput data to file !n“);for(i=0; i#include void fun (char *s, char *t) int i, sl;sl =
2、strlen(s);/*found*/for( i=0; ivoid fun(int a, int b, long *c)main() int a,b; long c;void NONO ( );printf(“Input a b:“); scanf(“%d%d“, fun(a, b, printf(“The result is: %dn“, c);NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *rf, *wf ;int i, a,b ; long c ;rf = fopen(“K:k0124010001in.dat“
3、, “r“) ;wf = fopen(“K:k0124010001out.dat“,“w“) ;for(i = 0 ; i #include #include void WriteText(FILE *);void ReadText(FILE *);main() FILE *fp;if(fp=fopen(“myfile4.txt“,“w“)=NULL) printf(“ open fail!n“); exit(0); WriteText(fp);fclose(fp);if(fp=fopen(“myfile4.txt“,“r“)=NULL) printf(“ open fail!n“); exi
4、t(0); ReadText(fp);fclose(fp);/*found*/void WriteText(FILE *fw_1_) char str81;printf(“nEnter string with -1 to end :n“);gets(str);while(strcmp(str,“-1“)!=0) /*found*/fputs(_2_str_,fw); fputs(“n“,fw);gets(str);void ReadText(FILE *fr) char str81;printf(“nRead file and output to screen :n“);fgets(str,8
5、1,fr);while( !feof(fr) ) /*found*/printf(“%s“,_3_str_);fgets(str,81,fr);二、程序改错题#include /*found*/void fun (long s, long t) long sl=10;*t = s % 10;while ( s 0) s = s/100;*t = s%10 * sl + *t;/*found*/sl = sl*100;main() long s, t;printf(“nPlease enter s:“); scanf(“%ld“, fun(s, printf(“The result is: %l
6、dn“, t);三、程序编写题#include #define N 16typedef struct char num10;int s; STREC;int fun( STREC *a, STREC *b )main() STREC sN=“GA05“,85,“GA03“,76,“GA02“,69,“GA04“,85,“GA01“,91,“GA07“,72,“GA08“,64,“GA06“,87,“GA015“,85,“GA013“,91,“GA012“,64,“GA014“,91,“GA011“,91,“GA017“,64,“GA018“,64,“GA016“,72;STREC hN;int
7、 i,n;FILE *out ;n=fun( s,h );printf(“The %d lowest score :n“,n);for(i=0;i#include int fun(char *fname ) FILE *fp; int i,n; float x;if(fp=fopen(fname, “w“)=NULL) return 0;for(i=1;i#include void fun ( int n, int *a ) int i, j, p, t;for ( j = 0; jai )/*found*/t=i;if ( p!=j ) t = aj; aj = ap; ap = t; vo
8、id putarr( int n, int *z ) int i;for ( i = 1; i void fun(int a, int b, long *c)main() int a,b; long c;void NONO ( );printf(“Input a b:“);scanf(“%d%d“, fun(a, b, printf(“The result is: %ldn“, c);NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *rf, *wf ;int i, a,b ; long c ;rf = fopen(“K:
9、k0124010001in.dat“, “r“) ;wf = fopen(“K:k0124010001out.dat“,“w“) ;for(i = 0 ; i #include int fun(char *source, char *target) FILE *fs,*ft; char ch;/*found*/if(fs=fopen(source, _r”1_)=NULL)return 0;if(ft=fopen(target, “w“)=NULL)return 0;printf(“nThe data in file :n“);ch=fgetc(fs);/*found*/while(!feof
10、(_2_) putchar( ch );/*found*/fputc(ch,_3_);ch=fgetc(fs);fclose(fs); fclose(ft);printf(“nn“);return 1;main() char sfname20 =“myfile1“,tfname20=“myfile2“;FILE *myf; int i; char c;myf=fopen(sfname,“w“);printf(“nThe original data :n“);for(i=1; ivoid fun (long s, long *t) int d;long sl=1;*t = 0;while ( s 0) d = s%10;/*found*/if (d%2=0) *t=d* sl+ *t;sl *= 10;/*found*/s = 10;main() long s, t;printf(“nPlease enter s:“); scanf(“%ld“, fun(s,