2009-2010学年度《计算机C语言程序设计》复习参考资料
{ int k,p;
for(p=0,k=p;p
8、以下程序统计从终端输入的字符中每个大写字母的个数,num [0]中统计字母A的个数,其它依次类推,用#表示结束输入,请填空。
#include “stdio.h” #include “ctype.h” main()
{ int num[26]={0},I; char c; while( (c=getch()) !=?#?)
if (isupper(c)) num[ c-?A? ]+=1; for(I=0;I<26;I++)
if(num[I]) printf(“%c: %d\\n ”,I+?A?,num[I]); }
9、 以下程序的输出结果是 GFEDCB 。
#include “stdio.h” main()
{ char b[]=”ABCDEFG”,*chp=&b[7]; while(--chp>&b[0]) putchar(*chp); putchar(?\\n?); }
10、 以下程序的输出结果是 。 “XYZA”
#include “stdio.h”
void fun ( char *a1,char *a2,int n ) { int k;
for ( k = 0; k < n ; k++)
a2[k] = (a1[k]-?A?-3+26)&+?A?; a2[n] = ?\\0?; } main()
{ char s1[5] = “ABCD ”, s2[5];
第36页 共38页
2009-2010学年度《计算机C语言程序设计》复习参考资料
fun (s1,s2,4); puts (s2 ); }
11、 以下程序的输出结果是 SO。
Main()
{ char *P[] = {“BOOL”, “OPK”, “H”, “SP”}; int i;
for ( i = 3; i>=0; i--,i--) printf(“%c”,*p[i]); printf(“\\n”); }
12、 当运行以下程序时从键盘输入字符 串 qwerty 和 abcd ,则程序的输出结果是 10。
#include “string.h” #include “stdio.h” strle ( char a[],char b[]) { int num = 0, n = 0;
while (*(a+num)!=?\\0?) num++;
while (b[n]) {*(a +num ) = b[n]; num++; n++; } return ( num ); } main()
{ char str1[81],str2[81],*p1 = str1,*p2 = str2; gets (p1 ); gets(p2 ); printf (“%d\\n”,strle( p1,p2 )); }
13、 以下程序的输出结果是
Itisis 。
#include “string.h” #include “ctype.h” void fun( char str[]) { int i,j;
for (i=0,j=0; str[i]; i++)
if( isalpha ( str[i]))str[j++] = str[i]; str[i] = ?\\0?; }
第37页 共38页
2009-2010学年度《计算机C语言程序设计》复习参考资料
main()
{ char ss[80] =”It is”; fun(ss );
printf(“%s\\n”,ss ); }
14、 以下 fun 函数的功能是将一个字符串的内容颠倒过来,请填空。
#include “striing.h” void fun ( char str[]) { char i, j, k;
for (i=0,j = strlen(str)-1 ; i 15、以下程序段的输出结果是 3 。 Printf(“%d\\n”,strlen ( “s\\n\\016\\0vend ” ) ); 16、以下程序段的输出结果是 goodgood 。 char s[20] = “goodgood!”, *sp = s; sp = sp + 2 ; sp = “to”; puts (s ) ; ) 第38页 共38页