2013年计算机二级C语言上机题库四_第2页

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年2月26日
  改错题
  下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。例如,给字符串s输入:AaaaBBb123CCccccd,则应输出结果:upper=6,lower=8
  请改正程序中的错误,使程序能得出正确的结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题程序:
  #include <conio.h>
  #include <stdio.h>
  /********found********/
  void fun(char *s, int a, int b)
  {
  while (*s)
  {
  /********found********/
  if (*s>='A' && *s<='Z')
  a++;
  /********found********/
  if (*s>='a' && *s<='z')
  b++;
  s++;
  }
  }
  main()
  {
  char s[100];
  int upper = 0, lower = 0;
  printf("\nPlease a string : ");
  gets(s);
  fun(s, &upper, &lower);
  printf("\n upper=%d lower=%d\n", upper, lower);
  }
  第1处:void fun (char *s,int a,int b)应改为void fun(char *s,int *a,int *b)
  第2处:a++;应改为(*a)++;
  第3处:b++;应改为(*b)++;

相关文章