《天亚教育计算机二级C上机考试复习资料.doc》由会员分享,可在线阅读,更多相关《天亚教育计算机二级C上机考试复习资料.doc(119页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、天亚教育计算机二级C上机考试复习资料(共50套题目)第1套 1、程序填空题 #include double fun(double e) int i; double s, x;/*found*/ s=0; i=_1_; x=1.0; while(xe)/*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: %fn,fun(e);2、程序修改题 #include #include /*found*/void fun (char s,
2、 char t) int i, d; d = strlen(s); for (i = 0; id; i+) ti = si; for (i = 0; id; i+) td+i = sd-1-i;/*found*/ t2*d-1 = 0;main() char s100, t100; printf(nPlease enter string S:); scanf(%s, s); fun(s, t); printf(nThe result is: %sn, t);3、程序设计题 #include #include void fun(char *s, char t)main() printf(nPle
3、ase enter string S:); scanf(%s, s); fun(s, t); printf(nThe result is: %sn, t);第2套 1、程序填空题 #include #include #include int fun(char *s) char *lp,*rp;/*found*/ lp= _1_ ; rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) & (lprp) ) /*found*/ lp+; rp _2_ ; /*found*/ if(lprp) _3_ ; else return 1;main() ch
4、ar s81; printf(Enter a string: ); scanf(%s,s); if(fun(s) printf(n%s is a Palindrome.nn,s); else printf(n%s isnt a Palindrome.nn,s);2、程序修改题 #include /*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) ;
5、main( ) int n = 5 ; printf( nThe value of function is: %lfn, fun ( n ) ) ;3、程序设计题 #include int prime(int n) int m; for(m=2;mn;m+) if (n % m = 0) return 0; return 1;void fun(int m, int k, int xx) /* 以下代码仅供参考 */ int j=0, t=m+1; while(jk) /* 按题目要求完成以下代码 */ main() printf( nPlease enter two integers:) ;
6、scanf(%d%d, &m, &n ) ; fun( m, n, zz) ; for( m = 0 ; m n ; m+ ) printf(%d , zzm) ; printf(n) ;第3套 1、程序填空题 #include /*found*/_1_ fun(char ch)/*found*/ if (ch=0 & _2_)/*found*/ return 9- (ch-_3_); return ch ;main() char c1, c2; printf(nThe result :n); c1=2; c2 = fun(c1); printf(c1=%c c2=%cn, c1, c2);
7、c1=8; c2 = fun(c1); printf(c1=%c c2=%cn, c1, c2); c1=a; c2 = fun(c1); printf(c1=%c c2=%cn, c1, c2);2、程序修改题#include void fun(char *p, char *b) int i, k=0; while(*p) i=1; while( i=3 & *p ) /*found*/ bk=p; k+; p+; i+; if(*p) /*found*/ bk+= ; bk=0;main() char a80,b80; printf(Enter a string: ); gets(a);
8、printf(The original string: ); puts(a); fun(a,b); printf(nThe string after insert space: ); puts(b); printf(nn);3、程序设计题 #include #include #define N 8struct slist double s; struct slist *next;typedef struct slist STREC;double fun( STREC *h )STREC * creat( double *s) STREC *h,*p,*q; int i=0; h=p=(STRE
9、C*)malloc(sizeof(STREC);p-s=0; while(is=si; i+; p-next=q; p=q; p-next=0; return h;outlist( STREC *h) STREC *p; p=h-next; printf(head); do printf(-%4.1f,p-s);p=p-next; while(p!=0); printf(nn);main() double sN=85,76,69,85,91,72,64,87,ave; STREC *h; h=creat( s ); outlist(h); ave=fun( h ); printf(ave= %
10、6.3fn,ave);第4套 1、程序填空题 #include /*found*/#define OK(i, t, n) (_1_%t=0) & (i/tn)int fun(int t1, int t2, int t3, int t4, int n) int count, t , maxt=t1; if (maxt t2) maxt = t2; if (maxt t3) maxt = t3; if (maxt t4) maxt = t4; count=1; /* 给count赋初值 */*found*/ for(t=1; t maxt*(n-1); _2_) if(OK(t, t1, n) |
11、 OK(t, t2, n)| OK(t, t3, n) | OK(t, t4, n) ) count+; /*found*/ return _3_;main() int t1=7, t2=5, t3=6, t4=4, n=10, r; r = fun(t1, t2, t3, t4, n); printf(The sound : %dn, r);2、程序修改题 #include #include /*found*/void fun(int a,int b,int c) if(a+bc & b+ca & a+cb) if(a=b & b=c) return 3; else if(a=b|b=c|a
12、=c) return 2;/*found*/ else retrun 1 else return 0;main() int a,b,c,shape; printf(nInput a,b,c: ); scanf(%d%d%d,&a,&b,&c); printf(na=%d, b=%d, c=%dn,a,b,c); shape =fun(a,b,c); printf(nnThe shape : %dn,shape);3、程序设计题 #include #include double fun(int n)main() int n; double sum; printf(nnInput n: ); sc
13、anf(%d,&n); sum=fun(n); printf(nnsum=%fnn,sum);第5套 1、程序填空题 #include int fun(int n) int a10000, i,j, count=0; for (i=2; i=n; i+) ai = i; i = 2; while (in) /*found*/ for (j=ai*2; j=n; j+=_1_) aj = 0; i+;/*found*/ while (_2_=0) i+; printf(nThe prime number between 2 to %dn, n); for (i=2; i=n; i+)/*foun
14、d*/ if (ai!=_3_) count+; printf( count%15?%5d:n%5d,ai); return count;main() int n=20, r; r = fun(n); printf(nThe number of prime is : %dn, r);2、程序修改题 #include #include void fun(int a,int *b,int *c) int i,j,d,y; for(i=3;i=a/2;i=i+2) /*found*/ Y=1; for(j=2;j=sqrt(double)i);j+) if(i%j=0) y=0; if(y=1) /
15、*found*/ d=a-i; for(j=2;j=sqrt(double)d);j+) if(d%j=0) y=0; if(y=1) *b=i; *c=d; main() int a,b,c; do printf(nInput a: ); scanf(%d,&a); while(a%2); fun(a,&b,&c); printf(nn%d = %d + %dn,a,b,c);3、程序设计题 #include double fun(int n)main() int n; double s; printf(nInput n: ); scanf(%d,&n); s=fun(n); printf(
16、nns=%fn,s);第6套 1、程序填空题 #include #define N 4/*found*/void fun(int (*t)_1_ ) int i, j; for(i=1; iN; i+) for(j=0; ji; j+) /*found*/ _2_ =tij+tji;/*found*/ _3_ =0; main() int tN=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; iN; i+) for(j=0; jN; j+) printf
17、(%2d ,tij); printf(n); fun(t); printf(nThe result is:n); for(i=0; iN; i+) for(j=0; jN; j+) printf(%2d ,tij); printf(n); 2、程序修改题#include #include #include /*found*/#define FU(m,n) (m/n)float fun(float a,float b,float c) float value; value=FU(a+b,a-b)+FU(c+b,c-b);/*found*/ Return(Value);main() float x
18、,y,z,sum; printf(Input x y z: ); scanf(%f%f%f,&x,&y,&z); printf(x=%f,y=%f,z=%fn,x,y,z); if (x=y|y=z)printf(Data error!n);exit(0); sum=fun(x,y,z); printf(The result is : %5.2fn,sum);3、程序设计题 #include void fun( char *a )main() char s81; printf(Enter a string:n);gets(s); fun( s ); printf(The string afte
19、r deleted:n);puts(s);第7套 1、程序填空题 #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=a0i ;/*found*/ a0i = _3_ ; aki = temp ; main() int xMN= 1,2,3,4,5,6,7,8,9,10,11,12 ,i,j; printf(The array before moving:nn); for(i=0; iM; i+) for(j
20、=0; jN; j+) printf(%3d,xij); printf(nn); fun(x,2); printf(The array after moving:nn); for(i=0; iM; i+) for(j=0; jN; j+) printf(%3d,xij); printf(nn); 2、程序修改题 #include #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( tj t j + 1 ) c
21、 = tj; tj = t j + 1 ; tj + 1 = c; main() char s81; printf( nPlease enter a character string: ); gets( s ); printf( nnBefore sorting:n %s, s ); fun( s ); printf( nAfter sorting decendingly:n %sn, s );3、程序设计题#include #include void fun( char *ss )void main( void ) printf( nPlease enter an character str
22、ing within 50 characters:n ); gets( tt ); printf( nnAfter changing, the stringn %s, tt ); fun(tt) ; printf( nbecomesn %s, tt );第8套 1、程序填空题 #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);
23、 n+; t+; return n;main() int x=-1; while(x0): ); scanf(%d,&x); printf(nThe result is: %dn,fun(x);2、程序修改题#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(%l
24、d, &s); fun(s, &t); printf(The result is: %ldn, t);3、程序设计题#include #define N 16typedef struct char num10; int s; STREC;void fun( STREC a ) STREC tmp; int i,j; for(i = 0; i N; i+) for(j = i+1; j N; j+) /* 请按题目要求完成以下代码 */ main() STREC sN=GA005,85,GA003,76,GA002,69,GA004,85,GA001,91,GA007,72,GA008,64,G
25、A006,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;iN; i+) if( (i)%4=0 )printf(n); printf(%s %4d ,si.num,si.s); printf(n); out = fopen(out.dat,w) ; for(i=0;iN; i+) if( (i)%4=0 & i) fprintf(out, n); fp
26、rintf(out, %4d ,si.s); fprintf(out,n); fclose(out) ;第9套 1、程序填空题 #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,16,47,38,29,11,32,54,42,21,3,10,i,j; printf(nThe or
27、iginal 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);2、程序修改题#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+n)/2;/*found*/ while(fabs(n-m)0.001) if(funx(r)*funx(n)0) m
28、=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);3、程序设计题 #include void fun( char *a, char *h,char *p )main() char s81,*t, *f; printf(Enter a string:n);gets(s); t=f=s; while(*t)t+; t-; while(*t=*)t-; whil
29、e(*f=*)f+; fun( s , f,t ); printf(The string after deleted:n);puts(s);第10套 1、程序填空题 #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|n0) printf(Please input(0n): );
30、 scanf(%ld,&n); printf(nThe result is: %ldn,fun(n);2、程序修改题 #include 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
31、is: %ldn, t);3、程序设计题 #include void fun(char p1, char p2)main() printf(Enter s1 and s2:n) ; scanf(%s%s, s1, s2) ; printf(s1=%sn, s1) ; printf(s2=%sn, s2) ; printf(Invoke fun(s1,s2):n) ; fun(s1, s2) ; printf(After invoking:n) ; printf(%sn, s1) ;第11套 1、程序填空题 #include #include double fun(double x) double f, t; int n; f = 1.0 + x;/*found*/ t = _1_; n = 1; do n+;/*found*/ t *= (-1.0)*x/_2_; f += t; /*found*/ while (_3_ = 1e-6); return f;