1、全国计算机C语言二级上机试题10套718071#include #include 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
2、=fgetc(fs); fclose(fs); fclose(ft); printf(nn); return 1;main() char sfname20 =myfile1,tfname20=myfile2; FILE *myf; int i; char c; myf=fopen(sfname,w); printf(nThe original data :n); for(i=1; i30; i+) c=A+rand()%25;fprintf(myf,%c,c); printf(%c,c); fclose(myf);printf(nn); if (fun(sfname, tfname) prin
3、tf(Succeed!); else printf(Fail!);0000000000000000000000000#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; main() long s, t; printf(nPlease enter s:); scanf(%ld, &s); fun(s, &t); printf(The result is: %
4、ldn, t);00000000000000000#include void fun(int a, int b, long *c)NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(C:WEXAMYS240001in.dat, r) ; wf = fopen(C:WEXAMYS240001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, &a, &b) ; fun(a, b, &c) ; fprintf
5、(wf, a=%d,b=%d,c=%ldn, a, b, c) ; fclose(rf) ; fclose(wf) ;main() int a,b; long c; printf(Input a, b:); scanf(%d,%d, &a, &b); fun(a, b, &c); printf(The result is: %ldn, c); NONO();72#include #include #define N 8typedef struct list int data; struct list *next; SLIST;SLIST *creatlist(int *);void outli
6、st(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 aN=12,87,45,32,91,16,20,48; head=creatlist(a); outlist(head);/*found*/ printf(nsum=%dn, fun(_3_);SLIST *creatlist(int a) SLIST *h,*p,*q; int i; h=p=(SLIST *)ma
7、lloc(sizeof(SLIST); for(i=0; idata=ai; 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(-Endn); 000000000000000000#include #include int fun (char *s, char
8、 *t1, char *t2 , char *w) int i; 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 s100, t1100, t2100, w100; printf(nPlease en
9、ter 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 : %sn, w); else printf(Error : strlen(t1) != strlen(t2)n);00000000000000000000#include #include
10、 void fun(char *s, char t)NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ char s100, t100 ; FILE *rf, *wf ; int i ; rf = fopen(C:WEXAMYS240001in.dat,r) ; wf = fopen(C:WEXAMYS240001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %s, s) ; fun(s, t) ; fprintf(wf, %sn, t) ; fclose(rf) ; fclose(wf) ;main() c
11、har s100, t100; printf(nPlease enter string S:); scanf(%s, s); fun(s, t); printf(nThe result is: %sn, t); NONO();73#include #define N 4fun(int tN, int n) int i, sum;/*found*/ _1_; for(i=0; in; i+)/*found*/ sum+=_2_ ; for(i=0; in; i+)/*found*/ sum+= tin-i-_3_ ; return sum;main() int tN=21,2,13,24,25,
12、16,47,38,29,11,32,54,42,21,3,10,i,j; printf(nThe original data:n); for(i=0; iN; i+) for(j=0; jN; j+) printf(%4d,tij); printf(n); printf(The result is: %d,fun(t,N);000000000000000#include #include double funx(double x) return(2*x*x*x-4*x*x+3*x-6); double fun( double m, double n)/*found*/ int r; r=(m+
13、n)/2;/*found*/ while(fabs(n-m)0.001) if(funx(r)*funx(n)0) m=r; else n=r; r=(m+n)/2; return r;main( ) double m,n, root; printf(Enter m n : n); scanf(%lf%lf,&m,&n); root=fun( m,n ); printf(root = %6.3fn,root);0000000000000000000#include void fun( char *a, char *h,char *p )NONO()/* 本函数用于打开文件,输入数据,调用函数,
14、输出数据,关闭文件。 */ FILE *in, *out ; int i ; char s81, *t, *f ; in = fopen(C:WEXAMYS240001in.dat,r) ; out = fopen(C:WEXAMYS240001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(in, %s, s) ; t=f=s; while(*t)t+; t-; while(*t=*)t-; while(*f=*)f+; fun(s, f, t); fprintf(out, %sn, s) ; fclose(in) ; fclose(out) ;main
15、() char s81,*t, *f; printf(Enter a string:n);gets(s); t=f=s; while(*t)t+; t-; while(*t=*)t-; while(*f=*)f+; fun( s , f,t ); printf(The string after deleted:n);puts(s); NONO();74#include #include struct student long sno; char name10; float score3;/*found*/_1_ fun(struct student a) int i; a.sno = 1000
16、2;/*found*/ strcpy(_2_, LiSi);/*found*/ for (i=0; i3; i+) _3_+= 1; return a;main() struct student s=10001,ZhangSan, 95, 80, 88, t; int i; printf(nnThe original data :n); printf(nNo: %ld Name: %snScores: ,s.sno, s.name); for (i=0; i3; i+) printf(%6.2f , s.scorei); printf(n); t = fun(s); printf(nThe d
17、ata after modified :n); printf(nNo: %ld Name: %snScores: ,t.sno, t.name); for (i=0; i3; i+) printf(%6.2f , t.scorei); printf(n);00000000000000#include #define N 20fun(int *a,int n,int x) int p=0,i; an=x; while( x!=ap ) p=p+1;/*found*/ if(P=n) return -1; else for(i=p;in;i+)/*found*/ ai+1=ai; return n
18、-1; main() int wN=-3,0,1,5,7,99,10,15,30,90,x,n,i; n=10; printf(The original data :n); for(i=0;in;i+) printf(%5d,wi); printf(nInput x (to delete): ); scanf(%d,&x); printf(Delete : %dn,x); n=fun(w,n,x); if ( n=-1 ) printf(*Not be found!*nn); else printf(The data after deleted:n); for(i=0;in;i+) print
19、f(%5d,wi);printf(nn); 0000000000000000000#include #define N 16typedef struct char num10; int s; STREC;int fun( STREC *a, STREC *b )main() STREC sN=GA05,85,GA03,76,GA02,69,GA04,85, GA01,91,GA07,72,GA08,64,GA06,87, GA015,85,GA013,91,GA012,64,GA014,91, GA011,91,GA017,64,GA018,64,GA016,72; STREC hN; int
20、 i,n;FILE *out ; n=fun( s,h ); printf(The %d lowest score :n,n); for(i=0;in; i+) printf(%s %4dn,hi.num,hi.s); printf(n); out = fopen(C:WEXAMYS240001out.dat,w) ; fprintf(out, %dn,n); for(i=0;in; i+) fprintf(out, %4dn,hi.s); fclose(out);75#include #include #define N 5typedef struct node int data; stru
21、ct 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=ai; q-next = NULL; if (h = N
22、ULL) 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(-Endn); main() NODE *head; int aN=2,4,6,8,10; head=creatlist(a); printf(nThe original list:n); ou
23、tlist(head); head=fun(head); printf(nThe list after inverting :n); outlist(head);000000000000000#include #include #define N 80void fun(char *s, char t) int i, j=0; for(i=0; istrlen(s); i+)/*found*/ if(i%2 & si%2=0) tj+=si;/*found*/ ti=0;main() char sN, tN; printf(nPlease enter string s : ); gets(s);
24、 fun(s, t); printf(nThe result is : %sn,t);000000000000000000#include void fun(int s10, int b, int *n, int mm, int nn) /* 以下代码仅供参考 */ int i,j,np=0; /* np用作b数组下标 */ for(i = 0 ; i nn ; i+) *n=np;NONO()/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, j, k ; int w1010, a100, n = 0, mm, nn ; rf = fopen(C:WEXAMYS240001in.dat,r) ; wf = fopen(C:WEXAMYS240001out.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
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1