首页 二级C语言题库

二级C语言题库

举报
开通vip

二级C语言题库二级C语言题库 第1套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> #define N 5 typedef struct { int num; char name[10]; char tel[10]; }STYPE; void check(); /**********found**********/ int fun(___1___ *std) { /**********found**********/ ___...

二级C语言题库
二级C语言题库 第1套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> #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<N; i++) /**********found**********/ fwrite(&std[i], sizeof(STYPE), 1, ___3___); fclose(fp); return (1); } main() { STYPE s[10]={ {1,"aaaaa","111111"},{1,"bbbbb","222222&qu ot;},{1,"ccccc","333333"}, {1,"ddddd","444444"},{1,"eeeee","555555"}}; int k; k=fun(s); if (k==1) { printf("Succeed!"); check(); } else printf("Fail!"); } void check() { FILE *fp; int i; STYPE s[10]; if((fp=fopen("myfile5.dat","rb"))==NULL) { printf("Fail !!\n"); exit(0); } printf("\nRead file and output to screen :\n"); printf("\n num name tel\n"); for(i=0; i<N; i++) { fread(&s[i],sizeof(STYPE),1, fp); printf("%6d %s %s\n",s[i].num,s[i].name,s[i].tel); } fclose(fp); } 二、程序改错题 #include <stdio.h> #include <string.h> 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<sl; i++) t[sl+i] = s[sl-i-1]; /************found************/ t[sl] = ‘\0’; } main() { char s[100], t[100]; printf("\nPlease enter string s:"); scanf("%s", s); fun(s, t); printf("The result is: %s\n", t); } 三、程序编写题 #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("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 <stdio.h> #include <string.h> #include <stdlib.h> 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 <stdio.h> /************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 <stdio.h> #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},{"GA 04",85}, {"GA01",91},{"GA07",72},{"GA08",64},{"GA06&qu ot;,87}, {"GA015",85},{"GA013",91},{"GA012",64},{"GA0 14",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<n; i++) printf("%s %4d\n",h[i].num,h[i].s); printf("\n"); out = fopen("K:\\k01\\24010001\\out.dat","w") ; fprintf(out, "%d\n",n); for(i=0;i<n; i++) fprintf(out, "%4d\n",h[i].s); fclose(out); } 第3套题 一、程序填空题 #include <math.h> #include <stdio.h> 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"); /**********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 <stdio.h> #include <stdlib.h> void fun ( int n, int *a ) { int i, j, p, t; for ( j = 0; j<n-1 ; j++ ) { p = j; /************found************/ for ( i=j+1; i<n-1 ; i++ ) if ( a[p]>a[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 <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: %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) ; } 第4套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> int fun(char *source, char *target) { FILE *fs,*ft; char ch; /**********found**********/ 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 <stdio.h> 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; } } main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t); printf("The result is: %ld\n", t); } 三、程序编写题 #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("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 <stdio.h> #include <stdlib.h> #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___; q=h; p=h->next; while(p!=NULL && x>p->data) { /**********found**********/ q=___2___; p=p->next; } s->next=p; /**********found**********/ q->next=___3___; } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <stdio.h> long fun (long num) { /************found************/ long k; do { k*=num%10 ; /************found************/ num\=10 ; } while(num) ; return (k) ; } main( ) { long n ; printf("\nPlease enter a number:") ; scanf("%ld",&n) ; printf("\n%ld\n",fun(n)) ; } 三、程序编写题 #include <stdio.h> float fun ( float *a , int n ) { } main() { float score[30]={90.5, 72, 80, 61.5, 55}, aver; void NONO ( ); aver = fun( score, 5 ); printf( "\nAverage score is: %5.2f\n", aver); NONO ( ); } void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, j ; float aver, score[5] ; 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 < 5 ; j++) fscanf(fp,"%f,",&score[j]) ; aver = fun(score, 5) ; fprintf(wf, "%5.2f\n", aver) ; } fclose(fp) ; fclose(wf) ; } 第6套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> #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___; } /**********found**********/ printf(" %d ",___2___); s->next=NULL; /**********found**********/ free(___3___); } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <stdio.h> /************found************/ fun (char a) { if ( *a ) { fun(a+1) ; /************found************/ printf("%c" *a) ; } } main( ) { char s[10]="abcd"; printf("处理前字符串=%s\n处理后字符串=", s); fun(s); printf("\n") ; } 三、程序编写题 #include <stdio.h> char *fun ( char *s, char *t) { } main( ) { char a[20],b[20]; void NONO ( ); printf("Input 1th string:") ; gets( a); printf("Input 2th string:") ; gets( b); printf("%s\n",fun (a, b )); NONO (); } void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i ; char a[20], b[20] ; 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", a, b) ; fprintf(wf, "%s\n", fun(a, b)) ; } fclose(fp) ; fclose(wf) ; } 第7套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> #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(___1___); /**********found**********/ q=p->___2___; } else { p=q; /**********found**********/ q=q->___3___; } } } } SLIST *creatlist(int *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <stdio.h> #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 <stdio.h> #define M 100 void fun ( int m, int *a , int *n ) { } 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 <stdio.h> #include <stdlib.h> #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!=___1___) { n++; /**********found**********/ if (p->data==ch) return ___2___; 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; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <string.h> #include <stdio.h> #include <ctype.h> fun ( char *p) { int i,t; char c[80]; /************found************/ For (i = 0,t = 0; p[i] ; i++) 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 <stdio.h> #include <string.h> void fun ( char *ss ) { } 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 <stdio.h> #include <stdlib.h> #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___=0; p=h->next; while(p) { (*n)++; /**********found**********/ p=p->___2___; } } main() { SLIST *head; int a[N]={12,87,45,32,91,16,20,48}, num; head=creatlist(a); outlist(head); /**********found**********/ fun(___3___, &num); printf("\nnumber=%d\n",num); } SLIST *creatlist(int a[]) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <stdio.h> #include <string.h> 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 ; } 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 <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: %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) ; } 第10套题 一、程序填空题 #include <stdio.h> #include <stdlib.h> #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___; /**********found**********/ p=p->___2___; } 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(___3___)); } SLIST *creatlist(int a[]) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; i++) { q=(SLIST *)malloc(sizeof(SLIST)); q->data=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 <stdio.h> #include <string.h> 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++; } } 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 <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("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) ; */ } 第11套题 一、程序填空题 #include <stdio.h> #include <string.h> #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___; i++) { len=strlen(ss[i]); if(i==0) *n=len; /**********found**********/ if(len ___2___ *n) { *n=len; k=i; } } /**********found**********/ return(___3___); } main() { char ss[M][N]={"shanghai","guangzhou","beijing","tianjing ","chongqing"}; int n,k,i; printf("\nThe original strings are :\n"); for(i=0;i<M;i++)puts(ss[i]); k=fun(ss,&n); printf("\nThe length of shortest string is : %d\n",n); printf("\nThe shortest string is : %s\n",ss[k]); } 二、程序改错题 #include <stdio.h> #include <string.h> 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 ); } main( ) { char tt[81]; printf( "\nPlease enter a string: " ); gets( tt ); printf( "\nThe result string is:\n%s", fun( tt ) ); } 三、程序编写题 #include <stdio.h> 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[] ) { } main() { int m, n, zz[100]; void NONO ( ); printf( "\nPlease enter an integer number between 10 and 100: " ); scanf( "%d", &n ); fun( n, &m, zz ); printf( "\n\nThere are %d non-prime numbers less than %d:", m, n ); for( n = 0; n < m; n++ ) printf( "\n %4d", zz[n] ); NONO(); } void NONO() { /* 请在此函数 输出数据,关闭文件。 */ int m, n, zz[100]; FILE *rf, *wf ; rf = fopen("K:\\k01\\24010001\\in.dat","r") ; wf = fopen("K:\\k01\\24010001\\out.dat","w") ; fscanf( rf, "%d", &n ); fun( n, &m, zz ); fprintf(wf, "%d\n%d\n", m, n ); for( n = 0; n < m; n++ ) fprintf(wf, "%d\n", zz[n] ); fclose(rf) ; fclose(wf) ; } 第12套题 一、程序填空题 #include <stdio.h> 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___; } else t1[k++]=s[i]; t2[j]=0; t1[k]=0; /**********found**********/ for(i=0; i<k; i++) ___2___; /**********found**********/ for(i=0; i<___3___; i++) s[k+i]=t2[i]; } main() { char s[80]="def35adh3kjsdf7"; printf("\nThe original string is : %s\n",s); fun(s); printf("\nThe result is : %s\n",s); } 二、程序改错题 #include <stdio.h> #include <string.h> #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 ; } } } } 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 <stdio.h> #include <string.h> #define M 81 int fun(char *ss, char c) { } 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 <stdio.h> 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]!= ___2___) n++; for(j=i+n+1; j>i; j--) /**********found**********/ s[j+1]= ___3___; 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 <stdio.h> 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 <stdio.h> void fun ( int a[3][3], int b[3][3]) { } 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 <stdio.h> void fun(char *s, int *t) { int i, n; n=0; /**********found**********/ for(i=0; ___1___ !=0; i++) /**********found**********/ if(s[i]>=‘0’&&s[i]<= ___2___ ) n++; /**********found**********/ ___3___ ; } 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 <stdio.h> 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) ; b = fun(&a, b) ; printf("%d %d\n", a, b) ; } 三、程序编写题 #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("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 <stdio.h> 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-___1___ ; else k=n-2; /**********found**********/ c=___2___ ; for(i=k-2; i>=1; i=i-2) s[i+2]=s[i]; /**********found**********/ s[1]=___3___ ; } main() { char s[80]="abcdefgh"; printf("\nThe original string is : %s\n",s); fun(s); printf("\nThe result is : %s\n",s); } 二、程序改错题 #include <stdio.h> 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 ; } 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 <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("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 <stdio.h> 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; i<n-2; i=i+2) { /**********found**********/ ___1___; /**********found**********/ for(j=___2___+2 ; j<n; j=j+2) if(s[t]>s[j]) t=j; if(t!=i) { x=s[i]; s[i]=s[t]; s[t]=x; } } for(i=1,j=0; i<n; i=i+2, j++) p[j]=s[i]; /**********found**********/ p[j]=___3___; } main() { char s[80]="baawrskjghzlicda", p[50]; printf("\nThe original string is : %s\n",s); fun(s,p); printf("\nThe result is : %s\n",p); } 二、程序改错题 #include <math.h> #include <stdio.h> 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 ; } main( ) { float n1, n2 ; printf("Enter a float number: ") ; scanf("%f", &n1) ; n2 = fun(n1) ; printf("%6.4f\n", n2) ; } 三、程序编写题 #include <stdio.h> #include <string.h> #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 <stdio.h> 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 <stdio.h> 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 <stdio.h> 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 <stdio.h> #define N 4 void fun(int (*t)[N], int m) { int i, j; /**********found**********/ for(i=0; i<N; ___1___ ) { for(j=N-1-m; j>=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<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } printf("Input m (m<=%d): ",N);scanf("%d",&m); fun(t,m); printf("\nThe result is:\n"); for(i=0; i<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } } 二、程序改错题 #include <stdio.h> #include <math.h> 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 <math.h> #include <stdio.h> 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 <stdio.h> #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<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } fun(t); printf("\nThe result is:\n"); for(i=0; i<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } } 二、程序改错题 #include <stdio.h> 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 <math.h> #include <stdio.h> 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 <stdio.h> #define N 4 void fun(int (*t)[N]) { int j ,r[N]; for(j=0; j<N; j++) r[j]=t[0][j]; for(j=0; j<N; j++) /**********found**********/ t[0][N-j-1]=t[j][___1___ ]; for(j=0; j<N; j++) t[j][0]=t[N-1][j]; /**********found**********/ for(j=N-1; 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<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } fun(t); printf("\nThe result is:\n"); for(i=0; i<N; i++) { for(j=0; j<N; j++) printf("%2d ",t[i][j]); printf("\n"); } } 二、程序改错题 #include <stdio.h> #include <math.h> /************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 <math.h> #include <stdio.h> 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 <stdio.h> 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<x<=999): "); scanf("%d",&x); } printf("\nThe result is: %d\n",fun(x)); } 二、程序改错题 #include <stdio.h> #include <string.h> void fun (char *s, char *t) { /************found************/ int i; sl = strlen(s); for (i=0; i<sl; i++) /************found************/ t[i] = s[sl-i]; for (i=0; i<sl; i++) t[sl+i] = s[i]; t[2*sl] = ‘\0’; } main() { char s[100], t[100]; printf("\nPlease enter string s:"); scanf("%s", s); fun(s, t); printf("The result is: %s\n", t); } 三、程序编写题 #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: %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 <stdio.h> 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 <stdio.h> /************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 <stdio.h> #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<N; i++) { if( (i)%4==0 )printf("\n"); printf("%s %4d ",s[i].num,s[i].s); } printf("\n"); out = fopen("K:\\k01\\24010001\\out.dat","w") ; for(i=0;i<N; i++) { if( (i)%4==0 && i) fprintf(out, "\n"); fprintf(out, "%4d ",s[i].s); } fprintf(out,"\n"); fclose(out) ; } 第23套题 一、程序填空题 #include <stdio.h> 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<n<100000000): "); scanf("%ld",&n); } printf("\nThe result is: %ld\n",fun(n)); } 二、程序改错题 #include <stdio.h> #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 <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: %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 <stdio.h> 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<n<100000000): "); scanf("%ld",&n); } printf("\nThe result is: %ld\n",fun(n)); } 二、程序改错题 #include <stdio.h> 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 <stdio.h> 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 <stdio.h> 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<n<100000000): "); scanf("%ld",&n); } fun(&n); printf("\nThe result is: %ld\n",n); } 二、程序改错题 #include <stdio.h> 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 <stdio.h>
本文档为【二级C语言题库】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_769254
暂无简介~
格式:doc
大小:169KB
软件:Word
页数:90
分类:计算机考试
上传时间:2017-10-07
浏览量:325