下列给定程序中,函数fun的功能是:分别统计字符串中大写字母和小写字母的个数。例如:给字符串s输入:AAaaBBb123CCccccd,则应该输出结果:upper=6,lower=8。请改正程序中的错误,使程序能得出正确的结果。注意,不要改动main函数,不得增行或删行,也不得更改程序的结构。
程序如下:
#include <conio.h>
#include <stdio.h>
void fun (char *s,int a, int b)
{
while(*s)
{
if (*s>='A' && *s<='Z')
a++;
if (*s>='a' && *s<='z')
b++;
s++;
}
}
main()
{
char s[100];int upper=0,lower=0;
clrscr();
printf("nPlease a string:");gets(s);
fun(s,&upper, &lower);
printf("n upper=%d lower=%dn",upper,lower);
}
程序如下:
#include <conio.h>
#include <stdio.h>
void fun (char *s,int a, int b)
{
while(*s)
{
if (*s>='A' && *s<='Z')
a++;
if (*s>='a' && *s<='z')
b++;
s++;
}
}
main()
{
char s[100];int upper=0,lower=0;
clrscr();
printf("nPlease a string:");gets(s);
fun(s,&upper, &lower);
printf("n upper=%d lower=%dn",upper,lower);
}