统计句子中大写字母个数
#include <stdio.h>int main()
{
int i=0;
char sentence;
int count=0;
printf("请输入一行英文句子:\n");
scanf("%s",&sentence);
while(i<=50&&i>=0)
{
if(sentence<=90&&sentence>=65)
{
count=count+1;
i=i+1;
}
else if(sentence<=122&&sentence>=97)
{
i=i+1;
}
}
printf("有%d个大写字母!\n",count);
return 0;
}
无法正常运行 #include <stdio.h>
int main()
{
int i = 0;
char sentence;
int count = 0;
printf("请输入一行英文句子:\n");
scanf("%s", sentence);
while (i <= 50 && i >= 0)
{
if (sentence <= 90 && sentence >= 65)
{
count = count + 1;
i = i + 1;
}
else if (sentence <= 122 && sentence >= 97)
{
i = i + 1;
}
}
printf("有%d个大写字母!\n", count);
return 0;
} 本帖最后由 baige 于 2020-8-2 11:50 编辑
#include <stdio.h>
int main()
{
int i=0;
char sentence;
int count=0;
printf("请输入一行英文句子:\n");
scanf("%s",sentence);//取地址符,去掉
while(sentence)
{
if(sentence<='Z'&&sentence>='A')// 当字字符>=A <= Z时 count+1;
count=count+1;
++i;
}
printf("有%d个大写字母!\n",count);
return 0;
} livcui 发表于 2020-8-2 11:48
字符数组会越界 baige 发表于 2020-8-2 11:49
多谢! baige 发表于 2020-8-2 11:51
字符数组会越界
{:10_245:}
页:
[1]