《大学c语言考试试题》由会员分享,可在线阅读,更多相关《大学c语言考试试题(5页珍藏版)》请在金锄头文库上搜索。
1、C 语言模拟试题一、判断1、 关系运算符=y&ch1;i-)for(j=1;jvoid main()int score,i,max,min,sum;max=-32768; min=32767; sum=0;for(i=1;imax or maxscore】 printf(Canceled max score:%dnCanceled min score:%dn,max,min);printf(Average score:%dn,【?】); 【(sun-max-min)/8】 2、功能:下面的程序是求1!+3!+5!+n!的和。#include main()long int f,s;int i,j
2、,n;【? 】 ; 【s=0】scanf(%d,for(i=1;i=j or jbool fun(char *c) 【char fun(char*c) 】if(*c=A)*c-=A-a;fun= c;【return *c】 main()char s81,p=s; 【*p=s】gets(s);while(*p)*p=fun(p);puts(*p); p+;putchar(n); 【putchar(*p)】2、功能:将字符串 s 中最后一次出现的子字符串 t1替换成字符串 t2,所形成的新串放在 w 所指的数组中,在此处,要求 t1和 t2所指字符串的长度相同。例如:当 s 所指字符串中的内容为a
3、bcdabfabc,t1中的内容为ab,t2中的内容为 99时,结果 w 所指数组中的内容 应为abcdabf99c。#include #include #include void fun (char *s, char *t1, char *t2 , char *w)char *p , *r, *a;strcpy( w, s );while ( w ) 【while(*w) or while (*w!0)】p = w; r = t1;while ( *r )if ( *r = *p ) 【if(*r=*p)】r+; p+;else break;if ( *r = /0 ) a = w; 【if
4、(*r=0)a=w】w+;r = t2;while ( *r )a = *r; 【*a=*r】a+;r+;main()char s100, t1100, t2100, w100;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 : %sn, w);else printf(nError : strlen(t1) != strlen(t2)n);