二级C语言题库

1058173211 贡献于2012-11-26

作者 k01  创建于2011-09-17 04:38:00   修改者aa  修改于2011-09-17 04:38:00字数73279

文档摘要:二级C语言题库
关键词:

第1套題 一、程式填空題 #include #include #define N 5 typedef struct { int num; char name[10]; char tel[10]; }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 = strlen(s); /************found************/ for( i=0; i<=s1; i ++) t[i] = s[i]; for (i=0; i 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("K:\\k01\\24010001\\in.dat", "r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第2套題 一、程式填空題 #include #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"); exit(0); } ReadText(fp); fclose(fp); } /**********found**********/ void WriteText(FILE ___1___) { char str[81]; printf("\nEnter string with -1 to end :\n"); gets(str); while(strcmp(str,"-1")!=0) { /**********found**********/ fputs(___2___,fw); fputs("\n",fw); gets(str); } } void ReadText(FILE *fr) { char str[81]; printf("\nRead file and output to screen :\n"); fgets(str,81,fr); {while( !feof(fr) ) /**********found**********/ printf("%s",___3___); 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", &s); fun(s, &t); printf("The result is: %ld\n", t); } 三、程式編寫題 #include #define N 16 typedef struct { char num[10]; int s; } STREC; int fun( STREC *a, STREC *b ) { } main() { STREC s[N]={{"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 h[N]; int 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<=10;i++) /**********found**********/ fprintf(___1___,"%d %f\n",i,sqrt((double)i)); printf("\nSucceed!!\n") ;fp(2)fclose(fp)(3)myfile3.txt /**********found**********/ ___2___; printf("\nThe data in file :\n"); /**********found**********/ if((fp=fopen(___3___,"r"))==NULL) return 0; fscanf(fp,"%d%f",&n,&x); while(!feof(fp)) { printf("%d %f\n",n,x); fscanf(fp,"%d%f",&n,&x); } fclose(fp); return 1; } main() { char fname[]="myfile3.txt"; fun(fname); } 二、程式改錯題 #include #include void fun ( int n, int *a ) { int i, j, p, t; for ( j = 0; ja[i] ) /************found************/ t=i; if ( p!=j ) { t = a[j]; a[j] = a[p]; a[p] = t; } } } void putarr( int n, int *z ) { int i; for ( i = 1; i <= n; i++, z++ ) { printf( "%4d", *z ); if ( !( i%10 ) ) printf( "\n" ); } printf("\n"); } main() { int aa[20]={9,3,0,4,1,2,5,6,8,10,7}, n=11; printf( "\n\nBefore sorting %d numbers:\n", n ); putarr( n, aa ); fun( n, aa ); printf( "\nAfter sorting %d numbers:\n", n ); putarr( n, aa ); } 三、程式編寫題 #include 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: %ld\n", c); NONO(); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen("K:\\k01\\24010001\\in.dat", "r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { c=b/10*1000+a/10*100+b%10*10+a%10; *c=(b%10)*1000+(a%10)*100+(b/10)*10+a/10; 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) ; } 第4套題 一、程式填空題 #include #include int fun(char *source, char *target) { FILE *fs,*ft; char ch; /**********found**********/) "r" (2 )fs (3)ft if((fs=fopen(source, ___1___))==NULL) return 0; if((ft=fopen(target, "w"))==NULL) return 0; printf("\nThe data in file :\n"); ch=fgetc(fs); /**********found**********/ while(!feof(___2___)) { putchar( ch ); /**********found**********/ fputc(ch,___3___); ch=fgetc(fs); } fclose(fs); fclose(ft); printf("\n\n"); return 1; } main() { char sfname[20] ="myfile1",tfname[20]="myfile2"; FILE *myf; int i; char c; myf=fopen(sfname,"w"); printf("\nThe original data :\n"); for(i=1; i<30; i++){ c='A'+rand()%25;fprintf(myf,"%c",c); printf("%c",c); } fclose(myf);printf("\n\n"); if (fun(sfname, tfname)) printf("Succeed!"); else printf("Fail!"); } 二、程式改錯題 #include void 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; if (d%2==0) (2 ) s/=10; if (d%2==0) (2 ) s/=10; } } main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t); printf("The result is: %ld\n", t); } 三、程式編寫題 #include #include void fun(char *s, char t[]) { Int i; for(i=0;i<100;i++) int i,j; While(s[i]) { int i = 0, j = 0; while(s[i]) if(i%2==0&&s[i]==0) t[j++]=s[i] if(i % 2 == 0 && s[i] % 2 == 0) t[j++] = s[i]; i++; } t[j] = 0; } 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("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第5套題 一、程式填空題 #include #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; void fun( SLIST *h, int x) { SLIST *p, *q, *s; s=(SLIST *)malloc(sizeof(SLIST)); /**********found**********/ s->data=___1__x_; q=h; p=h->next; while(p!=NULL && x>p->data) { /**********found**********/ q=___2__p_; p=p->next; } s->next=p; /**********found**********/ q->next=___3__s_; } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("\nThe list is NULL!\n"); else { printf("\nHead"); do { printf("->%d",p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { SLIST *head; int x; int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a); printf("\nThe list before inserting:\n"); outlist(head); printf("\nEnter a number : "); scanf("%d",&x); fun(head,x); printf("\nThe list after inserting:\n"); outlist(head); } 二、程式改錯題 #include long fun (long num) { /************found************/ long k=1; do { k*=num%10 ; /************found************/ num\=10 ;: (1)long k=1; (2)num/=10; } while(num) ; return (k) ; } main( ) { long n ; printf("\nPlease enter a number:") ; scanf("%ld",&n) ; printf("\n%ld\n",fun(n)) ; } 三、程式編寫題 #include float fun ( float *a , int n ); { For(n=0;n<5;n++) n=n+scor(i); Aver=n/5' int i; float aver=0.0; for(i=0;i #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; void fun( SLIST *p) { SLIST *t, *s; t=p->next; s=p; while(t->next != NULL) { s=t; /**********found**********/ t=t->___1_nest__; } /**********found**********/ printf(" %d ",___2_t_->data_); s->next=NULL; /**********found**********/ free(___t 3___);: (1) next (2) t->data (3) t } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("\nThe list is NULL!\n"); else { printf("\nHead"); do { printf("->%d",p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { SLIST *head; int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a); printf("\nOutput from head:\n"); outlist(head); printf("\nOutput from tail: \n"); while (head->next != NULL){ fun(head); printf("\n\n"); printf("\nOutput from head again :\n"); outlist(head); } } 二、程式改錯題 #include /************found************/ fun (char a) : (1) void fun(char *a) (2) print("%c",*a) { if ( *a ) { fun(a+1) ; /************found************/ printf("%c" *a) ; } } main( ) { char s[10]="abcd"; printf("處理前字串=%s\n處理後字串=", s); fun(s); printf("\n") ; } 三、程式編寫題 #include char *fun ( char *s, char *t) int i; char *p=s,*q=t; int n=0,m=0; while(*p) /*计算串s的长度n,其中p为临时指针*/ { n++; p++; } while(*q) /*计算串t的长度m,其中q为临时指针*/ { m++; q++; } if(n>=m) /*比较m和n的值,设置p指向较大的指针*/ p=s; else p=t; return p; { a[20]={"beijing"}; b[20]={"shanghai"}; Int i,j; For(i=1;i<20;i++) For(j=1;j<20;j++) If(i>j) Printf("%d",a[i]); Else if(i #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; void fun( SLIST *h) { SLIST *p, *q; p=h->next; if (p!=NULL) { q=p->next; while(q!=NULL) { if (p->data==q->data) { p->next=q->next; /**********found**********/ free(___q___); /**********found**********/ q=p->__next_2___; } else { p=q; /**********found**********/ q=q->____next_; } } } } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("\nThe list is NULL!\n"); else { printf("\nHead"); do { printf("->%d",p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main( ) { SLIST *head; int a[N]={1,2,2,3,4,4,4,5}; head=creatlist(a); printf("\nThe list before deleting :\n"); outlist(head); fun(head); printf("\nThe list after deleting :\n"); outlist(head); } 二、程式改錯題 #include #define N 20 void fun(int a[], int n) { int i, j, t, p; for (j = 0 ;j < n-1 ;j++) { /************found************/ p = j for (i = j+1;i < n; i++) if(a[i] < a[p]) /************found************/ p = j; t = a[p] ; a[p] = a[j] ; a[j] = t; } } main() { int a[N]={9,6,8,3,-1},i, m = 5; printf("排序前的數據:") ; for(i = 0;i < m;i++) printf("%d ",a[i]); printf("\n"); fun(a,m); printf("排序後的數據:") ; for(i = 0;i < m;i++) printf("%d ",a[i]); printf("\n"); } 三、程式編寫題 #include #define M 100 void fun ( int m, int *a , int *n ) { *n=0; int i; for(i=1;i<=m;i++) if(i%7==0||i%11==0) a[*n++]=i; } main( ) { int aa[M], n, k; void NONO ( ); fun ( 50, aa, &n ); for ( k = 0; k < n; k++ ) if((k+1)%20==0) printf("\n"); else printf( "%4d", aa[k] ); printf("\n") ; NONO( ); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n, j, k, aa[M], sum ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d,", &j) ; fun(j, aa, &n) ; sum = 0 ; for(k = 0 ; k < n ; k++) sum+=aa[k] ; fprintf(wf, "%d\n", sum) ; } fclose(fp) ; fclose(wf) ; } 第8套題 一、程式填空題 #include #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; SLIST *creatlist(char *); void outlist(SLIST *); int fun( SLIST *h, char ch) { SLIST *p; int n=0; p=h->next; /**********found**********/ while(p!=____0 NULL_) { n++; /**********found**********/ if (p->data==ch) return ___2 n___; 0或NULL (2)n (3)head,ch else p=p->next; } return 0; } main() { SLIST *head; int k; char ch; char a[N]={'m','p','g','a','w','x','r','d'}; head=creatlist(a); outlist(head); printf("Enter a letter:"); scanf("%c",&ch); /**********found**********/ k=fun(___3___); if (k==0) printf("\nNot found!\n"); else printf("The sequence number is : %d\n",k); } SLIST *creatlist(char *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("\nThe list is NULL!\n"); else { printf("\nHead"); do { printf("->%c",p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } 二、程式改錯題 #include #include #include fun ( char *p) { int i,t; char c[80]; /************found************/ For (i = 0,t = 0; p[i] ; i++) (1) for(i=0,t=0;p[i];i++) (2) c[t]='\0'; if(!isspace(*(p+i))) c[t++]=p[i]; /************found************/ c[t]="\0"; strcpy(p,c); } main( ) { char c,s[80]; int i=0; printf("Input a string:"); c=getchar(); while(c!='#') { s[i]=c;i++;c=getchar(); } s[i]='\0'; fun(s); puts(s); } 三、程式編寫題 #include #include void fun ( char *ss ) { Int i; While(i/2!=0) tt[i]=tt[i]+'A'; int i; for(i=1;i='a'&&ss[i]<='z') ss[i]-=32; } main( ) { char tt[81] ; void NONO ( ); printf( "\nPlease enter an string within 80 characters:\n" ); gets( tt ); printf( "\n\nAfter changing, the string\n \"%s\"", tt ); fun( tt ); printf( "\nbecomes\n \"%s\"\n", tt ); NONO ( ); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; char tt[81] ; int i ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%s", tt) ; fun( tt ) ; fprintf(wf, "%s\n", tt) ; } fclose(fp) ; fclose(wf) ; } 第9套題 一、程式填空題 #include #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; SLIST *creatlist(int *a); void outlist(SLIST *); void fun( SLIST *h, int *n) { SLIST *p; /**********found**********/ ___1__*n_=0; p=h->next; while(p) { (*n)++; /**********found**********/ p=p->___2 next___; } } main() { SLIST *head; int a[N]={12,87,45,32,91,16,20,48}, num; head=creatlist(a); outlist(head); /**********found**********/ fun(___3a[N]___, &num);(1) *n (2) next (3) head printf("\nnumber=%d\n",num); } SLIST *creatlist(int a[]) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d",p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } 二、程式改錯題 #include #include char * fun (char *s, char *t ) { char *p , *r, *a; /************found************/ a = Null; while ( *s ) { p = s; r = t; while ( *r ) /************found************/ if ( r == p ) { r++; p++; } else break; if ( *r == '\0' ) a = s; s++; } return a ;) a=NULL; (2) if(*r==*p) } main() { char s[100], t[100], *p; printf("\nPlease enter string S :"); scanf("%s", s ); printf("\nPlease enter substring t :"); scanf("%s", t ); p = fun( s, t ); if ( p ) printf("\nThe result is : %s\n", p); else printf("\nNot found !\n" ); } 三、程式編寫題 #include void fun(int a, int b, long *c) { *c=(a%10)*1000+(b/10)*100+(a/10)*10+b%10; int i,j=0; for(i=0;i #include #define N 8 typedef struct list { int data; struct list *next; } SLIST; SLIST *creatlist(int *); void outlist(SLIST *); int fun( SLIST *h) { SLIST *p; int s=0; p=h->next; while(p) { /**********found**********/ s+= p->___1_data__; /**********found**********/ p=p->___s2next___; } return s; } main() { SLIST *head; int a[N]={12,87,45,32,91,16,20,48}; head=creatlist(a); outlist(head); /**********found**********/ printf("\nsum=%d\n", fun(__head_3___)); } SLIST *creatlist(int a[]) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a[i]; p->next=q; p=q; } p->next=0; return h; } void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } 二、程式改錯題 #include #include void fun (char *s, char *t1, char *t2 , char *w) { char *p , *r, *a; strcpy( w, s ); while ( *w ) { p = w; r = t1; /************found************/ while ( r ) if ( *r == *p ) { r++; p++; } else break; if ( *r == '\0' ) { a = w; r = t2; while ( *r ){ /************found************/ *a = *r; a++; r++; } w += strlen(t2) ; } else w++; 1) while(*r) (2) *a=*r;a++;r++; } } main() { char s[100], t1[100], t2[100], w[100]; printf("\nPlease enter string S:"); scanf("%s", s); printf("\nPlease enter substring t1:"); scanf("%s", t1); printf("\nPlease enter substring t2:"); scanf("%s", t2); if ( strlen(t1)==strlen(t2) ) { fun( s, t1, t2, w); printf("\nThe result is : %s\n", w); } else printf("Error : strlen(t1) != strlen(t2)\n"); } 三、程式編寫題 #include #include void fun(char *s, char t[]) { int i; int i,j=0; for((i=0;i #include #define M 5 #define N 20 int fun(char (*ss)[N], int *n) { int i, k=0, len= N; /**********found**********/ for(i=0; i<___1_M__; i++) { len=strlen(ss[i]); if(i==0) *n=len; /**********found**********/ if(len ___2_<__ *n) { *n=len; k=i; } } /**********found**********/ return(___3__k_);: (1)M (2)< (3)k } main() { char ss[M][N]={"shanghai","guangzhou","beijing","tianjing","chongqing"}; int n,k,i; printf("\nThe original strings are :\n"); for(i=0;i #include char* fun( char tt[] ) { int i; for( i = 0; tt[i]; i++ ) /**********found***********/ if(( 'a' <= tt[i] )||( tt[i] <= 'z' ) ) /**********found***********/ tt[i] += 32; return( tt );(1)if(('a'<=tt[i])&&(tt[i]<='z')) (2)tt[i]-=32; } main( ) { char tt[81]; printf( "\nPlease enter a string: " ); gets( tt ); printf( "\nThe result string is:\n%s", fun( tt ) ); } 三、程式編寫題 #include int prime ( int m ) { int k = 2; while ( k <= m && (m%k)) k++; if (m == k ) return 1; else return 0; } void fun( int m, int *k, int xx[] ) { int i,j; int t=0; for(i=2;i void fun(char *s) { int i, j=0, k=0; char t1[80], t2[80]; for(i=0; s[i]!='\0'; i++) if(s[i]>='0' && s[i]<='9') { /**********found**********/ t2[j]=s[i]; ___1_j++__; } else t1[k++]=s[i]; t2[j]=0; t1[k]=0; /**********found**********/ for(i=0; i #include #define MAXLINE 20 fun ( char *pstr[6]) { int i, j ; char *p ; for (i = 0 ; i < 5 ; i++ ) { /**************found**************/ for (j = i + 1, j < 6, j++) { if(strcmp(*(pstr + i), *(pstr + j)) > 0) { p = *(pstr + i) ; /**************found**************/ *(pstr + i) = pstr + j ; *(pstr + j) = p ; } (1) for(j = i + 1; j < 6; j++) (2) *(pstr + i) =*( pstr + j); } } } main( ) { int i ; char *pstr[6], str[6][MAXLINE] ; for(i = 0; i < 6 ; i++) pstr[i] = str[i] ; printf( "\nEnter 6 string(1 string at each line): \n" ) ; for(i = 0 ; i < 6 ; i++) scanf("%s", pstr[i]) ; fun(pstr) ; printf("The strings after sorting:\n") ; for(i = 0 ; i < 6 ; i++) printf("%s\n", pstr[i]) ; } 三、程式編寫題 #include #include #define M 81 int fun(char *ss, char c) {int i; While(i>1&&i<10) { int cnt=0; char *p=ss; while(*p) {if(*p==c) cnt++; p++;} return cnt; } main() { char a[M], ch; void NONO ( ); printf("\nPlease enter a string:"); gets(a); printf("\nPlease enter a char:"); ch = getchar(); printf("\nThe number of the char is: %d\n", fun(a, ch)); NONO ( ); } void NONO ( ) {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int i ; FILE *rf, *wf ; char a[M], b[M], ch ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%s", a) ; fscanf(rf, "%s", b) ; ch = *b ; fprintf(wf, "%c=%d\n", ch, fun(a, ch)) ; } fclose(rf) ; fclose(wf) ; } 第13套題 一、程式填空題 #include void fun(char *s) { int i, j, n; for(i=0; s[i]!='\0'; i++) /**********found**********/ if(s[i]>='0' ___1&&___ s[i]<='9') { n=0; /**********found**********/ while(s[i+1+n]!= _0__) n++; for(j=i+n+1; j>i; j--) /**********found**********/ s[j+1]= _s[j]_3___;(1)&& (2)0 (3)s[j] s[j+1]='*'; i=i+1; } } main() { char s[80]="ba3a54cd23a"; printf("\nThe original string is : %s\n",s); fun(s); printf("\nThe result is : %s\n",s); } 二、程式改錯題 #include double fun ( int m ) { double y = 1.0 ; int i; /**************found**************/for(i=2;i<=m;i++) for(i = 2 ; i < m ; i++) /**************found**************/ y += 1 / (i * i) ; return( y ) ; } main( ) { int n = 5 ; printf( "\nThe result is %lf\n", fun ( n ) ) ; } 三、程式編寫題 #include void fun ( int a[3][3], int b[3][3]) { int c[3][3]; for(i=0,i<3;i++) for(j=0;j<3;j++) {c[i][j]=a[j][i]; b[i][j]=a[i][j]+c[i][j];} } main( ) /* 主程序 */ { int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, t[3][3] ; int i, j ; void NONO ( ); fun(a, t) ; for (i = 0 ; i < 3 ; i++) { for (j = 0 ; j < 3 ; j++) printf("%7d", t[i][j]) ; printf("\n") ; } NONO () ; } void NONO ( ) {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int i, j, k, a[3][3], t[3][3] ; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(k = 0 ; k < 5 ; k++) { for(i = 0 ; i < 3 ; i++) fscanf(rf, "%d %d %d", &a[i][0], &a[i][1], &a[i][2]) ; fun(a, t) ; for(i = 0 ; i < 3 ; i++) { for(j = 0 ; j < 3 ; j++) fprintf(wf, "%7d", t[i][j]) ; fprintf(wf, "\n") ; } } fclose(rf) ; fclose(wf) ; } 第14套題 一、程式填空題 #include void fun(char *s, int *t) { int i, n; n=0; /**********found**********/ for(i=0; ___s[i]1___ !=0; i++) /**********found**********/ if(s[i]>='0'&&s[i]<='9' ___2___ ) n++; /**********found**********/ *t=n; _3___ ;s[i] (2)'9' (3) *t=n; } main() { char s[80]="abcdef35adgh3kjsdf7"; int t; printf("\nThe original string is : %s\n",s); fun(s,&t); printf("\nThe result is : %d\n",t); } 二、程式改錯題 #include int fun(int *x,int y) { int t ; /**************found**************/ t = x ; x = y ; /**************found**************/ return(y) ; } main() { int a = 3, b = 8 ; printf("%d %d\n", a, b) ; 1) t=*x;*x=y; (2) return (t); b = fun(&a, b) ; printf("%d %d\n", a, b) ; } 三、程式編寫題 #include void fun (int *a, int *n) { Int i, *n=0; While(aa[i]%7=0||aa[i]%11=0) int i; *n=0; for(i=7;i<1000;i++) if (((i%7)==0)||((i%11)==0)&&((i%77)!=0) a[(*n)++]=i; } 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("K:\\k01\\24010001\\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) ; } 第15套題 一、程式填空題 #include void fun(char *s) { int i, n, k; char c; n=0; for(i=0; s[i]!='\0'; i++) n++; /**********found**********/ if(n%2==0) k=n-__i_1___ ; else k=n-2; /**********found**********/ c=__k_2___ ; for(i=k-2; i>=1; i=i-2) s[i+2]=s[i]; /**********found**********/ s[1]=___3_s[i(1) 1 (2) s[k] (3) c __ ; } main() { char s[80]="abcdefgh"; printf("\nThe original string is : %s\n",s); fun(s); printf("\nThe result is : %s\n",s); } 二、程式改錯題 #include long fun (int a, int n) { int j ; /**************found**************/ long s = 0, t = 1 ; for ( j = 0 ; j < n ; j++) t = t * 10 + a ; s = t ; for ( j = 1 ; j < n ; j++) { /**************found**************/ t += t % 10 ; s = s - t ; long s = 0,t = 0; (2) t = t / 10; } return(s) ; } main( ) { int a, n ; printf( "\nPlease enter a and n:") ; scanf( "%d%d", &a, &n ) ; printf( "The value of function is: %ld\n", fun ( a, n ) ); } 三、程式編寫題 #include #include 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("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第16套題 一、程式填空題 #include void fun(char *s, char *p) { int i, j, n, x, t; n=0; for(i=0; s[i]!='\0'; i++) n++; for(i=1; is[j]) t=j; if(t!=i) { x=s[i]; s[i]=s[t]; s[t]=x; } } for(i=1,j=0; i #include float fun ( float num ) { int s ; float n, t, pi ; t = 1 ; pi = 0 ; n = 1 ; s = 1 ; /**************found**************/ while(t >= num) { pi = pi + t ; n = n + 2 ; s = -s ; /**************found**************/ t = s % n ; } pi = pi * 4 ; return pi ; while(fabs(t)>=num) (2) t=s/n; } main( ) { float n1, n2 ; printf("Enter a float number: ") ; scanf("%f", &n1) ; n2 = fun(n1) ; printf("%6.4f\n", n2) ; } 三、程式編寫題 #include #include #define LEN 20 void fun (char a[], char b[], int n) { } main( ) { char str1[LEN], str2[LEN] ; int n ; void NONO ( ); printf("Enter the string:\n") ; gets(str1) ; printf("Enter the index of the char deleted:") ; scanf("%d", &n) ; fun(str1, str2, n) ; printf("The new string is: %s\n", str2) ; NONO() ; } void NONO ( ) {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ char str1[LEN], str2[LEN] ; int i, n ; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%s %d", str1, &n) ; fun(str1, str2, n) ; fprintf(wf, "%s\n", str2) ; } fclose(rf) ; fclose(wf) ; } 第17套題 一、程式填空題 #include void fun(char *s, char c) { int i, j, n; /**********found**********/ for(i=0; s[i]!=___1___ ; i++) if(s[i]==c) { /**********found**********/ n=___2___ ; while(s[i+1+n]!='\0') n++; for(j=i+n+1; j>i; j--) s[j+1]=s[j]; /**********found**********/ s[j+1]=___3___ ; i=i+1; } } main() { char s[80]="baacda", c; printf("\nThe string: %s\n",s); printf("\nInput a character: "); scanf("%c",&c); fun(s,c); printf("\nThe result is: %s\n",s); } 二、程式改錯題 #include double fun ( int x[]) { /************found************/ int sum = 0.0; int c=0, i=0; while (x[i] != 0) { if (x[i] > 0) { sum += x[i]; c++; } i++; } /************found************/ sum \= c; return sum; } main( ) { int x[1000]; int i=0; printf( "\nPlease enter some data (end with 0): " ); do { scanf("%d", &x[i]); } while (x[i++] != 0); printf("%f\n", fun ( x )); } 三、程式編寫題 #include double fun(int n) { } main() { int n; double s; void NONO ( ); printf("\nPlease enter N:"); scanf("%d", &n); s = fun(n); printf("the result is: %f\n", s); NONO(); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n ; double s; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第18套題 一、程式填空題 #include #define N 4 void fun(int (*t)[N], int m) { int i, j; /**********found**********/ for(i=0; i=0; j--) /**********found**********/ t[i][j+___2___ ]=t[i][j]; /**********found**********/ for(j=0; j<___3___; j++) t[i][j]=0; } } main() { int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j, m; printf("\nThe original array:\n"); for(i=0; i #include int fun( int high ) { int sum = 0, n=0, j, yes; /************found************/ while ((high >= 2) && (n < 10) { yes = 1; for (j=2; j<=high/2; j++ ) if (high % j ==0 ){ /************found************/ yes=0; break } if (yes) { sum +=high; n++; } high--; } return sum ; } main ( ) { printf("%d\n", fun (100)); } 三、程式編寫題 #include #include double fun() { } main() { void NONO ( ); printf("Root =%f\n", fun()); NONO(); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *wf ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; fprintf(wf, "%f\n", fun()) ; fclose(wf) ; } 第19套題 一、程式填空題 #include #define N 4 void fun(int (*t)[N]) { int i, j, x; /**********found**********/ for(i=0; i<___1___; i++) { /**********found**********/ x=t[i][___2___] ; for(j=N-1; j>=1; j--) t[i][j]=t[i][j-1]; /**********found**********/ t[i][___3___]=x; } } main() { int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j; printf("The original array:\n"); for(i=0; i double fun( double q ) { int n; double s,t; n = 2; s = 2.0; while (s<=q) { t=s; /************found************/ s=s+(n+1)/n; n++; } printf("n=%d\n",n); /************found************/ return s; } main ( ) { printf("%f\n", fun(50)); } 三、程式編寫題 #include #include int fun( int t) { } main() /* 主函數 */ { int n; void NONO ( ); n=1000; printf("n = %d, f = %d\n",n, fun(n)); NONO(); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n, s ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%d\n", s) ; } fclose(fp) ; fclose(wf) ; } 第20套題 一、程式填空題 #include #define N 4 void fun(int (*t)[N]) { int j ,r[N]; for(j=0; j=0;___2___ ) t[N-1][N-1-j]=t[j][N-1]; for(j=N-1; j>=0; j--) /**********found**********/ t[j][N-1]=r[___3___]; } main() { int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j; printf("\nThe original array:\n"); for(i=0; i #include /************found************/ f( double x) { if (x == 0.0 || x == 2.0) return 0.0; else if (x < 0.0) return (x -1)/(x-2); else return (x +1)/(x-2); } double fun( int n ) { int i; double s=0.0, y; for (i= -n; i<=n; i++) {y=f(1.0*i); s += y;} /************found************/ return s } main ( ) { printf("%f\n", fun(5) ); } 三、程式編寫題 #include #include double fun( int m ) { } main() { void NONO ( ); printf("%f\n", fun(20)); NONO(); } void NONO ( ) {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n ; double s ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第21套題 一、程式填空題 #include int fun(int x) { int n, s1, s2, s3, t; /**********found**********/ n=__1__; t=100; /**********found**********/ while(t<=__2__) { s1=t%10; s2=(t/10)%10; s3=t/100; if(s1+s2+s3==15) { printf("%d ",t); n++; } /**********found**********/ __3__; } return n; } main() { int x=-1; while(x>999||x<0) { printf("Please input(0 #include void fun (char *s, char *t) { /************found************/ int i; sl = strlen(s); for (i=0; i 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: %ld\n", c); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第22套題 一、程式填空題 #include int fun(int x) { int n, s1, s2, s3, t; n=0; t=100; /**********found**********/ while(t<=__1__){ /**********found**********/ s1=t%10; s2=(__2__)%10; s3=t/100; /**********found**********/ if(s1+s2+s3==__3__) { printf("%d ",t); n++; } t++; } return n; } main() { int x=-1; while(x<0) { printf("Please input(x>0): "); scanf("%d",&x); } printf("\nThe result is: %d\n",fun(x)); } 二、程式改錯題 #include /************found************/ void fun (long s, long t) { long sl=10; s /= 10; *t = s % 10; /************found************/ while ( s < 0) { s = s/100; *t = s%10*sl + *t; sl = sl * 10; } } main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t); printf("The result is: %ld\n", t); } 三、程式編寫題 #include #define N 16 typedef struct { char num[10]; int s; } STREC; void fun( STREC a[] ) { } main() { STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85}, {"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87}, {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91}, {"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}}; int i;FILE *out ; fun( s ); printf("The data after sorted :\n"); for(i=0;i unsigned long fun(unsigned long n) { unsigned long x=0, s, i; int t; s=n; /**********found**********/ i=__1__; /**********found**********/ while(__2__) { t=s%10; if(t%2==0){ /**********found**********/ x=x+t*i; i=__3__; } s=s/10; } return x; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 #define M 5 /************found************/ int fun(int n, int xx[][]) { int i, j, sum=0; printf( "\nThe %d x %d matrix:\n", M, M ); for( i = 0; i < M; i++ ) { for( j = 0; j < M; j++ ) /************found************/ printf( "%f ", xx[i][j] ); printf("\n"); } for( i = 0 ; i < n ; i++ ) sum += xx[i][i]+xx[i][ n-i-1 ]; return( sum ); } main( ) { int aa[M][M]={{1,2,3,4,5},{4,3,2,1,0}, {6,7,8,9,0},{9,8,7,6,5},{3,4,5,6,7}}; printf ( "\nThe sum of all elements on 2 diagnals is %d.",fun( M, aa )); } 三、程式編寫題 #include 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: %ld\n", c); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第24套題 一、程式填空題 #include unsigned long fun(unsigned long n) { unsigned long x=0; int t; while(n) { t=n%10; /**********found**********/ if(t%2==__1__) /**********found**********/ x=__2__+t; /**********found**********/ n=__3__; } return x; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 void fun (long s, long *t) { int d; long sl=1; /************found************/ t = 0; while ( s > 0) { d = s%10; /************found************/ if (d%2 == 0) { *t = d * sl + *t; sl *= 10; } s /= 10; } } main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t); printf("The result is: %ld\n", t); } 三、程式編寫題 #include void fun(char p1[], char p2[]) { } main() { char s1[80], s2[40] ;void NONO (); printf("Enter s1 and s2:\n") ; scanf("%s%s", s1, s2) ; printf("s1=%s\n", s1) ; printf("s2=%s\n", s2) ; printf("Invoke fun(s1,s2):\n") ; fun(s1, s2) ; printf("After invoking:\n") ; printf("%s\n", s1) ; NONO() ; } void NONO () {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int i ; FILE *rf, *wf ; char s1[80], s2[40] ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%s", s1) ; fscanf(rf, "%s", s2) ; fun(s1, s2) ; fprintf(wf, "%s\n", s1) ; } fclose(rf) ; fclose(wf) ; } 第25套題 一、程式填空題 #include void fun(unsigned long *n) { unsigned long x=0, i; int t; i=1; while(*n) /**********found**********/ { t=*n % __1__; /**********found**********/ if(t%2!= __2__) { x=x+t*i; i=i*10; } *n =*n /10; } /**********found**********/ *n=__3__; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 double fun ( int n ) { double result = 1.0 ; /************found************/ if n = = 0 return 1.0 ; while( n >1 && n < 170 ) /************found************/ result *= n-- return result ; } main ( ) { int n ; printf("Input N:") ; scanf("%d", &n) ; printf("\n\n%d! =%lf\n\n", n, fun(n)) ; } 三、程式編寫題 #include #include long fun ( char *p) { /* 以下代碼僅供參考 */ int i, len, t; /* len為串長,t為正負標識 */ long x=0; len=strlen(p); if(p[0]=='-') { t=-1; len--; p++; } else t=1; /* 以下完成數字字串轉換為一個數字 */ return x*t; } main() /* 主函數 */ { char s[6];void NONO (); long n; printf("Enter a string:\n") ; gets(s); n = fun(s); printf("%ld\n",n); NONO ( ); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i ; char s[20] ; long n ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%s", s) ; n = fun(s); fprintf(wf, "%ld\n", n) ; } fclose(fp) ; fclose(wf) ; } 第26套題 一、程式填空題 #include double fun(int n) { int i; double s, t; /**********found**********/ s=__1__; /**********found**********/ for(i=1; i<=__2__; i++) { t=2.0*i; /**********found**********/ s=s+(2.0*i-1)*(2.0*i+1)/__3__; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0): "); scanf("%d",&n); } printf("\nThe result is: %f\n",fun(n)); } 二、程式改錯題 #include int fun (char *str,char *substr) { int i,j,k,num=0; /************found************/ for(i = 0, str[i], i++) for(j=i,k=0;substr[k]==str[j];k++,j++) /************found************/ If(substr[k+1]=='\0') { num++; break; } return num; } main() { char str[80],substr[80]; printf("Input a string:") ; gets(str); printf("Input a substring:") ; gets(substr); printf("%d\n",fun(str,substr)); } 三、程式編寫題 #include #include double fun ( double eps) { } main( ) { double x;void NONO (); printf("Input eps:") ; scanf("%lf",&x); printf("\neps = %lf, PI=%lf\n", x, fun(x)); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i ; double x ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%lf", &x) ; fprintf(wf, "%lf\n", fun(x)) ; } fclose(fp) ; fclose(wf) ; } 第27套題 一、程式填空題 #include double fun(int n) { int i, k; double s, t; s=0; /**********found**********/ k=__1__; for(i=1; i<=n; i++) { /**********found**********/ t=__2__; s=s+k*(2*i-1)*(2*i+1)/(t*t); /**********found**********/ k=k*__3__; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0): "); scanf("%d",&n); } printf("\nThe result is: %f\n",fun(n)); } 二、程式改錯題 #include int fun ( int m ) { int k = 2; while ( k <= m && (m%k)) /************found************/ k++ /************found************/ if (m = k ) return 1; else return 0; } main( ) { int n; printf( "\nPlease enter n: " ); scanf( "%d", &n ); if ( fun ( n ) ) printf( "YES\n" ); else printf( "NO!\n" ); } 三、程式編寫題 #include #include void fun(int a[], int n , int *max, int *d ) { } main() { int i, x[20], max , index, n = 10;void NONO (); for (i=0;i < n;i++) {x[i] = rand()%50; printf("%4d", x[i]) ; } printf("\n"); fun( x, n , &max, &index); printf("Max =%5d , Index =%4d\n",max, index ); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, x[20], max , index, n = 10, j ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { for(j = 0 ; j < n ; j++) fscanf(fp, "%d,", &x[j]) ; fun( x, n , &max, &index); fprintf(wf, "Max=%d,Index=%d\n", max, index) ; } fclose(fp) ; fclose(wf) ; } 第28套題 一、程式填空題 #include double fun(double e) { int i, k; double s, t, x; s=0; k=1; i=2; /**********found**********/ x=__1__/4; /**********found**********/ while(x __2__ e) { s=s+k*x; k=k* (-1); t=2*i; /**********found**********/ x=__3__/(t*t); i++; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); } 二、程式改錯題 #include /************found************/ void fun ( int n ) { int a, b, c, k; double s; s = 0.0; a = 2; b = 1; for ( k = 1; k <= n; k++ ) { /************found************/ s = s + (Double)a / b; c = a; a = a + b; b = c; } return s; } main( ) { int n = 5; printf( "\nThe value of function is: %lf\n", fun ( n ) ); } 三、程式編寫題 #include #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("K:\\k01\\24010001\\out.dat","w") ; fprintf(wf, "max=%d\n", fun(arr)) ; fclose(wf) ; } 第29套題 一、程式填空題 #include double fun(double e) { int i; double s, x; /**********found**********/ s=0; i=__1__; x=1.0; while(x>e){ /**********found**********/ __2__; /**********found**********/ x=(2.0*i-1)/((__3__)*(2.0*i)); s=s+x; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); } 二、程式改錯題 #include #include /************found************/ void fun (char s, char t) { int i, d; d = strlen(s); for (i = 0; i #include 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("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第30套題 一、程式填空題 #include #include #include char *fun(char *s) { int i, j, k, n; char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char)); p=(char*)malloc(n*sizeof(char)); j=0; k=0; for(i=0; i='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) { /**********found**********/ t[j]=__1__; j++;} else { p[k]=s[i]; k++; } } /**********found**********/ for(i=0; i<__2__; i++) t[j+i]=p[i]; /**********found**********/ t[j+k]= __3__; return t; } main() { char s[80]; printf("Please input: "); scanf("%s",s); printf("\nThe result is: %s\n",fun(s)); } 二、程式改錯題 #include #include void fun (char *s, char *t1, char *t2 , char *w) { char *p , *r, *a=s; strcpy( w, s ); /************found************/ while ( w ) { p = w; r = t1; while ( *r ) /************found************/ IF ( *r == *p ) { r++; p++; } else break; if ( *r == '\0' ) a = w; w++; } r = t2; while ( *r ){ *a = *r; a++; r++; } } main() { char s[100], t1[100], t2[100], w[100]; printf("\nPlease enter string S:"); scanf("%s", s); printf("\nPlease enter substring t1:"); scanf("%s", t1); printf("\nPlease enter substring t2:"); scanf("%s", t2); if ( strlen(t1)==strlen(t2) ) { fun( s, t1, t2, w); printf("\nThe result is : %s\n", w); } else printf("\nError : strlen(t1) != strlen(t2)\n"); } 三、程式編寫題 #include #include 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("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第31套題 一、程式填空題 #include #define N 3 #define M 4 /**********found**********/ void fun(int (*a)[N], int __1__) { int i,temp ; /**********found**********/ for(i = 0 ; i < __2__ ; i++) { temp=a[0][i] ; /**********found**********/ a[0][i] = __3__ ; a[k][i] = temp ; } } main() { int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j; printf("The array before moving:\n\n"); for(i=0; i #include void fun( char t[] ) { char c; int i, j; /**********found***********/ for( i = strlen( t ); i; i-- ) for( j = 0; j < i; j++ ) /**********found***********/ if( t[j] < t[ j + 1 ] ) { c = t[j]; t[j] = t[ j + 1 ]; t[j + 1 ] = c; } } main() { char s[81]; printf( "\nPlease enter a character string: " ); gets( s ); printf( "\n\nBefore sorting:\n \"%s\"", s ); fun( s ); printf( "\nAfter sorting decendingly:\n \"%s\"\n", s ); } 三、程式編寫題 #include #include void fun( char *ss ) { } void main( void ) { char tt[51];void NONO (); printf( "\nPlease enter an character string within 50 characters:\n" ); gets( tt ); printf( "\n\nAfter changing, the string\n \"%s\"", tt ); fun(tt) ; printf( "\nbecomes\n \"%s\"", tt ); NONO(); } void NONO () { /* 請在此函數內打開檔,輸入測試數據,調用 fun 函數, 輸出數據,關閉檔。 */ char tt[51], ch; FILE *rf, *wf ; int len, i=0 ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; while(i < 10) { fgets( tt, 50, rf ); len = strlen(tt) - 1 ; ch = tt[len] ; if(ch == '\n' || ch == 0x1a) tt[len] = 0 ; fun(tt); fprintf( wf, "%s\n", tt ); i++ ; } fclose(rf) ; fclose(wf) ; } 第32套題 一、程式填空題 #include #define M 3 #define N 5 void fun(int (*a)[N],int k) { int i,j,p,temp; /**********found**********/ for(p=1; p<= __1__; p++) for(i=0; i #include #define M 10 int a[M][M] = {0} ; /**************found**************/ void fun(int **a, int m) { int j, k ; for (j = 0 ; j < m ; j++ ) for (k = 0 ; k < m ; k++ ) /**************found**************/ a[j][k] = k * j ; } main ( ) { int i, j, n ; printf ( " Enter n : " ) ; scanf ("%d", &n ) ; fun ( a, n ) ; for ( i = 0 ; i < n ; i++) { for (j = 0 ; j < n ; j++) printf ( "%4d", a[i][j] ) ; printf ( "\n" ) ; } } 三、程式編寫題 #include 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: %ld\n", c); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第33套題 一、程式填空題 #include #define M 3 #define N 4 void fun(int (*a)[N]) { int i=0,j,find=0,rmax,c,k; while( (i double fun ( int m ) { double y = 1.0 ; int i ; /**************found**************/ for(i = 2 ; i < m ; i++) /**************found**************/ y -= 1 /(i * i) ; return( y ) ; } main( ) { int n = 5 ; printf( "\nThe result is %lf\n", fun ( n ) ) ; } 三、程式編寫題 #include #include int fun(int score[], int m, int below[]) { } main( ) { int i, n, below[9] ;void NONO (); 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() ; } void NONO () {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int i, j, n, below[10], score[10] ; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\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) ; } 第34套題 一、程式填空題 #include #include #define N 80 void fun(char *s, int n, char *t) { int len,i,j=0; len=strlen(s); /**********found**********/ if(n>=len) strcpy(__1__); else { /**********found**********/ for(i=len-n; i<=len-1; i++) t[j++]= __2__ ; /**********found**********/ t[j]= __3__ ; } } main() { char s[N],t[N]; int n; printf("Enter a string: ");gets(s); printf( "Enter n:"); scanf("%d",&n); fun(s,n,t); printf("The string t : "); puts(t); } 二、程式改錯題 #include int fun(int m) { int i, k ; for (i = m + 1 ; ; i++) { for (k = 2 ; k < i ; k++) /**************found**************/ if (i % k != 0) break ; /**************found**************/ if (k < i) return(i); } } void main() { int n ; n = fun(20) ; printf("n=%d\n", n) ; } 三、程式編寫題 #include void fun ( int x, int pp[], int *n ) { } main( ) { int x, aa[1000], n, i ;void NONO (); 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") ; NONO( ) ; } void NONO () {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int x, aa[1000], n, i, j ; FILE *fp ; fp = fopen("K:\\k01\\24010001\\out.dat","w") ; for(j = 0 ; j < 10 ; j++) { x = 30 + j ; fun(x, aa, &n) ; for(i = 0 ; i < n ; i++) fprintf(fp, "%d ", aa[i]) ; fprintf(fp, "\n") ; } fclose(fp) ; } 第35套題 一、程式填空題 #include #include #include int fun(char *s) { char *lp,*rp; /**********found**********/ lp= __1__ ; rp=s+strlen(s)-1; while((toupper(*lp)==toupper(*rp)) && (lp /**************found**************/ fun (int n ) { int a = 2, b = 1, c, k ; double s=0.0 ; for ( k = 1; k <= n; k++ ) { s = s + 1.0 * a / b ; /**************found**************/ c = a; a += b; b += c; } return(s) ; } main( ) { int n = 5 ; printf( "\nThe value of function is: %lf\n", fun ( n ) ) ; } 三、程式編寫題 #include void fun(int m, int k, int xx[]) { /* 以下代碼僅供參考 */ int i, j=1, t=m+1; while(j<=k) { /* 以下完成判斷素數,並存放到數組xx中 */ } } main() { int m, n, zz[1000] ;void NONO (); printf( "\nPlease enter two integers:") ; scanf("%d%d", &m, &n ) ; fun( m, n, zz) ; for( m = 0 ; m < n ; m++ ) printf("%d ", zz[m]) ; printf("\n") ; NONO( ) ; } void NONO () {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int m, n, zz[1000], i ; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%d %d", &m, &n) ; fun(m, n, zz) ; for( m = 0 ; m < n ; m++ ) fprintf(wf, "%d ", zz[m]) ; fprintf(wf, "\n") ; } fclose(rf) ; fclose(wf) ; } 第36套題 一、程式填空題 #include int fun(char *s) { int n=0, flag=0; while(*s!='\0') { if(*s!=' ' && flag==0) { /**********found**********/ __1__ ; flag=1;} /**********found**********/ if (*s==' ') flag= __2__ ; /**********found**********/ __3__ ; } return n; } main() { char str[81]; int n; printf("\nEnter a line text:\n"); gets(str); n=fun(str); printf("\nThere are %d words in this text.\n\n",n); } 二、程式改錯題 #include #define N 20 int fun ( float *s, int n, float *aver ) { float ave, t = 0.0 ; int count = 0, k, i ; for ( k = 0 ; k < n ; k++ ) /**************found**************/ t = s[k] ; ave = t / n ; for ( i = 0 ; i < n ; i++ ) if ( s[ i ] < ave ) count++ ; /**************found**************/ *aver = Ave ; return count ; } main() { float s[30], aver ; int m, i ; printf ( "\nPlease enter m: " ) ; scanf ("%d", &m ) ; printf ( "\nPlease enter %d mark :\n ", m ) ; for( i = 0 ; i < m ; i++ ) scanf ( "%f", s + i ) ; printf( "\nThe number of students : %d \n" , fun ( s, m, &aver ) ); printf( "Ave = %f\n", aver ) ; } 三、程式編寫題 #include void fun(int *s, int t, int *k) { } main( ) { int a[10]={876,675,896,101,301,401,980,431,451,777}, k ;void NONO (); fun(a, 10, &k) ; printf("%d, %d\n", k, a[k]) ; NONO( ) ; } void NONO () {/* 本函數用於打開檔,輸入測試數據,調用fun函數,輸出數據,關閉檔。*/ int a[10], i, k, j ; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { for(j = 0 ; j < 10 ; j++) fscanf(rf, "%d", &a[j]) ; fun(a, 10, &k) ; fprintf(wf, "%d,%d\n", k, a[k]) ; } fclose(rf) ; fclose(wf) ; } 第37套題 一、程式填空題 #include int fun(char *s, char *t) { int n=0; while(*s) { if(*s < 97) { /**********found**********/ *(t+n)= __1__ ; n++; } /**********found**********/ __2__ ; } *(t+n)=0; /**********found**********/ return __3__ ; } main() { char s[81],t[81]; int n; printf("\nEnter a string:\n"); gets(s); n=fun(s,t); printf("\nThere are %d letter which ASCII code is less than 97: %s\n",n,t); } 二、程式改錯題 #include int fun(double x[], int n) { /************found************/ int j, c=0, double xa=0.0; for (j=0; j xa) c++; return c; } main ( ) { double x[100] = {193.199, 195.673, 195.757, 196.051, 196.092, 196.596, 196.579, 196.763}; printf("%d\n", fun (x, 8)); } 三、程式編寫題 #include float fun(int m, int n) { } main() /* 主函數 */ { void NONO (); printf("P=%f\n", fun (12,8)); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, m, n ; float s; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d,%d", &m, &n) ; s = fun(m, n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第38套題 一、程式填空題 #include #include #include int fun(char *s) { int sum=0; while(*s) { /**********found**********/ if( isdigit(*s) ) sum+= *s- __1__ ; /**********found**********/ __2__; } /**********found**********/ return __3__ ; } main() { char s[81]; int n; printf("\nEnter a string:\n\n"); gets(s); n=fun(s); printf("\nThe result is: %d\n\n",n); } 二、程式改錯題 #include int fun( int k ) { int m=0, mc=0 ; while ((k >= 2) && (mc < 10)) { /************found************/ if ((k%13 = 0) || (k%17 = 0)) { m = m+ k; mc++; } k--; } return m; /************found************/ _____ main ( ) { printf("%d\n", fun (500)); } 三、程式編寫題 #include #include double fun( int n) { } main() /* 主函數 */ { void NONO (); printf("s =%f\n", fun ( 1000) ); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n ; double s; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第39套題 一、程式填空題 #include #include #include void fun(char *s) { int k[26]={0},n,i,max=0; char ch; while(*s) { if( isalpha(*s) ) { /**********found**********/ ch=tolower(__1__); n=ch-'a'; /**********found**********/ k[n]+= __2__ ; } s++; /**********found**********/ if(max #include /************found************/ void fun( int k ) { int n; double s, w, p, q; n = 1; s = 1.0; while ( n <= k ) { w = 2.0 * n; p = w - 1.0; q = w + 1.0; s = s * w *w/p/q; n++; } /************found************/ return s } main ( ) { printf("%f\n", fun (10)); } 三、程式編寫題 #include double fun( int n ) { } main() /* 主函數 */ { void NONO (); printf("%f\n", fun(10)); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n ; double s ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = fun(n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第40套題 一、程式填空題 #include #include #define N 5 #define M 8 void fun(char (*ss)[M]) { char *ps[N],*tp; int i,j,k; for(i=0; i #include /************found************/ fun(int n) { double sum, s0, s1, s2, s; int k; sum = 1.0; if (n <= 2) sum = 0.0; s0 = 0.0; s1 = 0.0; s2 = 1.0; for (k = 4; k <= n; k++) { s = s0 + s1 + s2; sum += sqrt(s); s0 = s1; s1 = s2; s2 = s; } /************found************/ return sum } main ( ) { int n; printf("Input N="); scanf("%d", &n); printf("%f\n", fun(n) ); } 三、程式編寫題 #include #include double fun(double x , int n) { } main() { void NONO (); printf("%f\n", fun(0.3,10)); NONO(); } void NONO () {/* 本函數用於打開檔,輸入數據,調用函數,輸出數據,關閉檔。 */ FILE *fp, *wf ; int i, n ; double s, x ; fp = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%lf,%d", &x, &n) ; s = fun(x, n) ; fprintf(wf, "%f\n", s) ; } fclose(fp) ; fclose(wf) ; } 第41套題 一、程式填空題 #include double f1(double x) { return x*x; } double f2(double x, double y) { return x*y; } double fun(double a, double b) { /**********found**********/ __1__ (*f)(); double r1, r2; /**********found**********/ f = __2__ ; /* point fountion f1 */ r1 = f(a); /**********found**********/ f = __3__ ; /* point fountion f2 */ r2 = (*f)(a, b); return r1 + r2; } main() { double x1=5, x2=3, r; r = fun(x1, x2); printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n",x1, x2, r); } 二、程式改錯題 #include #include typedef struct aa { int data; struct aa *next; }NODE; int fun(NODE *h) { int sum = 0 ; NODE *p; /***********found**********/ p=h; while(p) { if(p->data%2==0) sum +=p->data; /***********found**********/ p=h->next; } return sum; } NODE *creatlink(int n) { NODE *h, *p, *s; int i; h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++) { s=(NODE *)malloc(sizeof(NODE)); s->data=rand()%16; s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h; } outlink(NODE *h, FILE *pf) { NODE *p; p = h->next; fprintf(pf ,"\n\nTHE LIST :\n\n HEAD " ); while(p) { fprintf(pf ,"->%d ",p->data ); p=p->next; } fprintf (pf,"\n"); } outresult(int s, FILE *pf) { fprintf(pf,"\nThe sum of even numbers : %d\n",s);} main() { NODE *head; int even; head=creatlink(12); head->data=9000; outlink(head , stdout); even=fun(head); printf("\nThe result :\n"); outresult(even, stdout); } 三、程式編寫題 #include #include #define N 80 int fun(char *str) { } main() { char s[N] ;void NONO (); printf("Enter a string: ") ; gets(s) ; printf("\n\n") ; puts(s) ; if(fun(s)) printf(" YES\n") ; else printf(" NO\n") ; NONO() ; } void NONO () {/* 請在此函數內打開檔,輸入測試數據,調用 fun 函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i ; char s[N] ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%s", s) ; if(fun(s)) fprintf(wf, "%s YES\n", s) ; else fprintf(wf, "%s NO\n", s) ; } fclose(rf) ; fclose(wf) ; } 第42套題 一、程式填空題 #include #include #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; /**********found**********/ p = __1__ ; while (p) { /**********found**********/ q = __2__ ; while (q) { /**********found**********/ if (p->data __3__ q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } p = p->next; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE)); h->next = NULL; for(i=0; idata=a[i]; q->next = NULL; if (h->next == NULL) h->next = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after sorting :\n"); outlist(head); } 二、程式改錯題 #include #include typedef struct aa { int data; struct aa *next; } NODE; int fun ( NODE *h ) { int max=-1; NODE *p; /***********found**********/ p=h ; while(p) { if(p->data>max ) max=p->data; /***********found**********/ p=h->next ; } return max; } outresult(int s, FILE *pf) { fprintf(pf,"\nThe max in link : %d\n",s);} NODE *creatlink(int n, int m) { NODE *h, *p, *s; int i; h=p=(NODE *)malloc(sizeof(NODE));h->data=9999; for(i=1; i<=n; i++) { s=(NODE *)malloc(sizeof(NODE)); s->data=rand()%m; s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h; } outlink(NODE *h, FILE *pf) { NODE *p; p=h->next; fprintf(pf,"\nTHE LIST :\n\n HEAD "); while(p) { fprintf(pf,"->%d ",p->data); p=p->next; } fprintf(pf,"\n"); } main() { NODE *head; int m; head=creatlink(12, 100); outlink(head , stdout); m=fun(head); printf("\nTHE RESULT :\n"); outresult(m, stdout); } 三、程式編寫題 #include void fun(int (*s)[10], int *b, int *n, int mm, int nn) { } main() { int w[10][10] = {{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j ; int a[100] = {0}, n = 0 ;void NONO (); printf("The matrix:\n") ; for(i = 0 ; i < 3 ; i++) { for(j = 0 ; j < 4 ; j++) printf("%3d",w[i][j]) ; printf("\n") ; } fun(w, a, &n, 3, 4) ; printf("The A array:\n") ; for(i = 0 ; i < n ; i++) printf("%3d",a[i]);printf("\n\n") ; NONO() ; } void NONO () {/* 請在此函數內打開檔,輸入測試數據,調用 fun 函數,輸出數據,關閉檔。*/ FILE *rf, *wf ; int i, j, k ; int w[10][10], a[100], n = 0, mm, nn ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(k = 0 ; k < 5 ; k++) { fscanf(rf, "%d %d", &mm, &nn) ; for(i = 0 ; i < mm ; i++) for(j = 0 ; j < nn ; j++) fscanf(rf, "%d", &w[i][j]) ; fun(w, a, &n, mm, nn) ; for(i = 0 ; i < n ; i++) fprintf(wf, "%3d", a[i]) ; fprintf(wf, "\n") ; } fclose(rf) ; fclose(wf) ; } 第43套題 一、程式填空題 #include #include #define N 5 typedef struct node { int data; struct node *next; } NODE; /**********found**********/ __1__ * fun(NODE *h) { NODE *p, *q, *r; p = h; if (p == NULL) return NULL; q = p->next; p->next = NULL; while (q) { /**********found**********/ r = q->__2__; q->next = p; p = q; /**********found**********/ q = __3__ ; } return p; } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; idata=a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]={2,4,6,8,10}; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); head=fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 二、程式改錯題 #include #include #define N 80 void fun(char *s, char t[]) { int i, j=0; for(i=0; i<(int)strlen(s); i++) /***********found**********/ if(i%2 && s[i]%2==0) t[j++]=s[i]; /***********found**********/ t[i]='\0'; } main() { char s[N], t[N]; printf("\nPlease enter string s : "); gets(s); fun(s, t); printf("\nThe result is : %s\n",t); } 三、程式編寫題 #include void fun(int s[][10], int b[], int *n, int mm, int nn) { /* 以下代碼僅供參考 */ int i,j,np=0; /* np用作b數組下標 */ *n=np; } main() { int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j; int a[100]={0}, n=0;void NONO (); printf("The matrix:\n"); for(i=0; i<3; i++) { for(j=0;j<4; j++)printf("%3d",w[i][j]); printf("\n"); } fun(w,a,&n,3,4); printf("The A array:\n"); for(i=0;i #include #define N 5 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q, *r; /**********found**********/ p = h->__1__; /**********found**********/ if (p==__2__) return; q = p->next; p->next = NULL; while (q) { r = q->next; q->next = p; /**********found**********/ p = q; q = __3__; } h->next = p; } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE)); h->next = NULL; for(i=0; idata=a[i]; q->next = NULL; if (h->next == NULL) h->next = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]={2,4,6,8,10}; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 二、程式改錯題 #include #include #define N 80 int fun(char *s, char *t) { int n; char *p , *r; n=0; while ( *s ) { p=s; /*********found**********/ r=p; while(*r) if(*r==*p) { r++; p++; } else break; /*********found**********/ if(*r= 0) n++; s++; } return n; } main() { char a[N],b[N]; int m; printf("\nPlease enter string a : "); gets(a); printf("\nPlease enter substring b : "); gets( b ); m=fun(a, b); printf("\nThe result is : m = %d\n",m); } 三、程式編寫題 #include #include #define M 3 #define N 20 void fun(char a[M][N], char *b) { /* 以下代碼僅供參考 */ int i; *b=0; } main() { char w[M][N]={"AAAA","BBBBBBB","CC"}, a[100]; int i ;void NONO (); printf("The string:\n"); for(i=0; i #include #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; p = h; while (p) { /**********found**********/ q = __1__ ; /**********found**********/ while (__2__) { if (p->data > q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } /**********found**********/ p = __3__ ; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; idata=a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 二、程式改錯題 #include #include void fun (char *s) { /**********found***********/ while(*s!='@') { if(*s>='A' && *s<='Z' || *s>='a' && *s<='z') { if(*s=='Z') *s='A'; else if(*s=='z') *s='a'; else *s += 1; } /**********found***********/ (*s)++; } } main() { char s[80]; printf("\n Enter a string with length < 80. :\n\n "); gets(s); printf("\n The string : \n\n "); puts(s); fun ( s ); printf ("\n\n The Cords :\n\n "); puts(s); } 三、程式編寫題 #include #define N 80 void fun(int *w, int p, int n) { } main() { int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int i,p,n=15;void NONO (); printf("The original data:\n"); for(i=0; i double f1(double x) { return x*x; } double f2(double x, double y) { return x*y; } /**********found**********/ __1__ fun(int i, double x, double y) { if (i==1) /**********found**********/ return __2__(x); else /**********found**********/ return __3__(x, y); } main() { double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n\n",x1, x2, r); } 二、程式改錯題 #include /**********found**********/ char fun(char *s, char *t) { int sl=0,tl=0; char *ss, *tt; ss=s; tt=t; while(*ss) { sl++; /**********found**********/ (*ss)++; } while(*tt) { tl++; /**********found**********/ (*tt)++; } if(tl>sl) return t; else return s; } main() { char a[80],b[80]; printf("\nEnter a string : "); gets(a); printf("\nEnter a string again : "); gets(b); printf("\nThe longer is :\n\n\"%s\"\n",fun(a,b)); } 三、程式編寫題 #include #include #define N 80 void fun1(char *w) /* 本函數的功能是將字串中字元迴圈左移一個位置 */ { int i; char t; t=w[0]; for(i=0;i<(int)strlen(w)-1;i++) w[i]=w[i+1]; w[strlen(w)-1]=t; } void fun(char *w, int m) /* 可調用fun1函數左移字元 */ { } main() { char a[N]= "ABCDEFGHIJK"; int m;void NONO (); printf("The original string:\n");puts(a); printf("\n\nEnter m: ");scanf("%d",&m); fun(a,m); printf("\nThe string after moving:\n");puts(a); printf("\n\n"); NONO(); } void NONO () {/* 請在此函數內打開檔,輸入測試數據,調用 fun 函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; char a[N] ; int m, i ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(rf, "%d %s", &m, a) ; fun(a, m) ; fprintf(wf, "%s\n", a) ; } fclose(rf) ; fclose(wf) ; } 第47套題 一、程式填空題 #include void fun(char *s, int a, double f) { /**********found**********/ __1__ fp; char ch; fp = fopen("file1.txt", "w"); fprintf(fp, "%s %d %f\n", s, a, f); fclose(fp); fp = fopen("file1.txt", "r"); printf("\nThe result :\n\n"); ch = fgetc(fp); /**********found**********/ while (!feof(__2__)) { /**********found**********/ putchar(__3__); ch = fgetc(fp); } putchar('\n'); fclose(fp); } main() { char a[10]="Hello!"; int b=12345; double c= 98.76; fun(a,b,c); } 二、程式改錯題 #include void fun(char *s) { int i,j; for(i=0,j=0; s[i]!='\0'; i++) if(s[i]>='0' && s[i]<='9') /**********found**********/ s[j]=s[i]; /**********found**********/ s[j]="\0"; } main() { char item[80]; printf("\nEnter a string : ");gets(item); printf("\n\nThe string is : \"%s\"\n",item); fun(item); printf("\n\nThe string of changing is : \"%s\"\n",item ); } 三、程式編寫題 #include #define M 3 #define N 4 void fun(char s[][N], char *b) { int i,j,n=0; for(i=0; i < N;i++) /* 請填寫相應語句完成其功能 */ { } b[n]='\0'; } main() { char a[100],w[M][N]={{'W','W','W','W'},{'S','S','S','S'},{'H','H','H','H'}}; int i,j;void NONO (); printf("The matrix:\n"); for(i=0; i #include void fun(char *s, int a, double f) { /**********found**********/ __1__ fp; char str[100], str1[100], str2[100]; int a1; double f1; fp = fopen("file1.txt", "w"); fprintf(fp, "%s %d %f\n", s, a, f); /**********found**********/ __2__ ; fp = fopen("file1.txt", "r"); /**********found**********/ fscanf(__3__,"%s%s%s", str, str1, str2); fclose(fp); a1 = atoi(str1); f1 = atof(str2); printf("\nThe result :\n\n%s %d %f\n", str, a1, f1); } main() { char a[10]="Hello!"; int b=12345; double c= 98.76; fun(a,b,c); } 二、程式改錯題 #include #include #include #define N 10 typedef struct ss { char num[10]; int s; } STU; STU *fun(STU a[], int m) { STU b[N], *t; int i,j,k; /**********found**********/ t=(STU *)calloc(sizeof(STU),m) for(i=0; i b[j].s) j=i; /**********found**********/ t(k)=b(j); b[j].s=0; } return t; } outresult(STU a[], FILE *pf) { int i; for(i=0; i10 ) { printf("\nGive the number of the students who have better score: "); scanf("%d",&m); } pOrder=fun(a,m); printf("***** THE RESULT *****\n"); printf("The top :\n"); for(i=0; i #define N 80 int fun(int a[], int n) { } main() { 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;void NONO (); printf("The original data :\n"); for(i=0; i #define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(char *filename) { FILE *fp; int i, j; STU s[N], t; /**********found**********/ fp = fopen(filename, __1__); fread(s, sizeof(STU), N, fp); fclose(fp); for (i=0; i #include void fun ( char s[], int n ) { char a[80] , *p; int i; /**********found***********/ s=p; for(i=0; i #define N 50 #define M 11 void fun( int *a, int *b) { } double rnd() { static t=29,c=217,m=1024,r=0; r=(r*t+c)%m; return((double)r/m); } main() { int age[N], i, d[M];void NONO (int d[M]); for(i=0; i #define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(char *filename, STU n) { FILE *fp; /**********found**********/ fp = fopen(__1__, "rb+"); /**********found**********/ fseek(__2__, -(long)sizeof(STU), SEEK_END); /**********found**********/ fwrite(&n, sizeof(STU), 1, __3__); fclose(fp); } main() { STU t[N]={ {10001,"MaChao", 91, 92, 77}, {10002,"CaoKai", 75, 60, 88}, {10003,"LiSi", 85, 70, 78}, {10004,"FangFang", 90, 82, 87}, {10005,"ZhangSan", 95, 80, 88}}; STU n={10006,"ZhaoSi", 55, 70, 68}, ss[N]; int i,j; FILE *fp; fp = fopen("student.dat", "wb"); fwrite(t, sizeof(STU), N, fp); fclose(fp); fp = fopen("student.dat", "rb"); fread(ss, sizeof(STU), N, fp); fclose(fp); printf("\nThe original data :\n\n"); for (j=0; j #include typedef struct aa { int data; struct aa *next; } NODE; NODE *Creatlink(int n, int m) { NODE *h=NULL, *p, *s; int i; /**********found***********/ p=(NODE )malloc(sizeof(NODE)); h=p; p->next=NULL; for(i=1; i<=n; i++) { s=(NODE *)malloc(sizeof(NODE)); s->data=rand()%m; s->next=p->next; p->next=s; p=p->next; } /**********found***********/ return p; } outlink(NODE *h) { NODE *p; p=h->next; printf("\n\nTHE LIST :\n\n HEAD "); while(p) { printf("->%d ",p->data); p=p->next; } printf("\n"); } main() { NODE *head; head=Creatlink(8,22); outlink(head); } 三、程式編寫題 #include #include #define N 80 int fun( char *s) { } main() { char line[N]; int num=0;void NONO (); printf("Enter a string :\n"); gets(line); num=fun( line ); printf("The number of word is : %d\n\n",num); NONO(); } void NONO () {/* 請在此函數內打開檔,輸入測試數據,調用 fun 函數,輸出數據,關閉檔。 */ FILE *rf, *wf ; int i, num ; char line[N], *p ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i = 0 ; i < 10 ; i++) { fgets(line, N, rf) ; p = strchr(line, '\n') ; if(p != NULL) *p = 0 ; num = fun(line) ; fprintf(wf, "%d\n", num) ; } fclose(rf) ; fclose(wf) ; }

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 5 金币 [ 分享文档获得金币 ] 0 人已下载

下载文档