跪求一道C语言程序题答案!
统计下面一段文字中的大写字母、小写字母、数字、空格字符的个数。"ThEclassisgoing,ifyoudon'tlisten,you8maygoout!"用指针、指针...
统计下面一段文字中的大写字母、小写字母、数字、空格字符的个数。
"ThE class is going,if you don't listen,you 8 may go out!"
用指针、指针数组来做!
谢谢了,我在线等! 展开
"ThE class is going,if you don't listen,you 8 may go out!"
用指针、指针数组来做!
谢谢了,我在线等! 展开
5个回答
展开全部
可统计任何字符串,运行时输入
#include<stdio.h>
#define MAX 100/*定义字符串最大长度*/
void main()
{
char c[MAX],*p;
int dx=0,xx=0,kg=0,sz=0;/*变量分别记录大写,小写,空格,数字的个数*/
printf("\nPlease input a string:");
gets(c);/*接受字符串*/
p=c;/*p指向第一个字符*/
while(*p!='\0')
{
if(*p==' ')
kg++;
if(*p>='0' && *p<='9')
sz++;
if(*p>='a' && *p<='z')
xx++;
if(*p>='A' && *p<='Z')
dx++;
p++;
}
printf("\nxiao xie zi mu you %d ge",xx);
printf("\nda xie zi mu you %d ge",dx);
printf("\nshu zi you %d ge",sz);
printf("\nkong ge you %d ge",kg);
printf("\n");
}
#include<stdio.h>
#define MAX 100/*定义字符串最大长度*/
void main()
{
char c[MAX],*p;
int dx=0,xx=0,kg=0,sz=0;/*变量分别记录大写,小写,空格,数字的个数*/
printf("\nPlease input a string:");
gets(c);/*接受字符串*/
p=c;/*p指向第一个字符*/
while(*p!='\0')
{
if(*p==' ')
kg++;
if(*p>='0' && *p<='9')
sz++;
if(*p>='a' && *p<='z')
xx++;
if(*p>='A' && *p<='Z')
dx++;
p++;
}
printf("\nxiao xie zi mu you %d ge",xx);
printf("\nda xie zi mu you %d ge",dx);
printf("\nshu zi you %d ge",sz);
printf("\nkong ge you %d ge",kg);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int main()
{
char str[]="ThE class is going,if you don't listen,you 8 may go out!";
char* p;
int HighCount=0,LowCount=0,NumCount=0,EmptyCount=0;
for (p=str;(*p)!='\0';p++)
{
if ((*p)>='A'&&(*p)<='Z') HighCount++;
else if ((*p)>='a'&&(*p)<='z') LowCount++;
else if ((*p)>='0'&&(*p)<='9') NumCount++;
else if ((*p)==' ') EmptyCount++;
}
printf("大写字母有%d个\n小写字母有%d个\n数字有%d个\n空格有%d个\n",HighCount,LowCount,NumCount,EmptyCount);
return 0;
}
int main()
{
char str[]="ThE class is going,if you don't listen,you 8 may go out!";
char* p;
int HighCount=0,LowCount=0,NumCount=0,EmptyCount=0;
for (p=str;(*p)!='\0';p++)
{
if ((*p)>='A'&&(*p)<='Z') HighCount++;
else if ((*p)>='a'&&(*p)<='z') LowCount++;
else if ((*p)>='0'&&(*p)<='9') NumCount++;
else if ((*p)==' ') EmptyCount++;
}
printf("大写字母有%d个\n小写字母有%d个\n数字有%d个\n空格有%d个\n",HighCount,LowCount,NumCount,EmptyCount);
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
以下程序调试通过,保证正确运行:
main(){
char s[]="ThE class is going,if you don't listen,you 8 may go out!";
char *p=s;
int upper=0,lower=0,number=0,space=0;
while(*p){
if (*p>='A' && *p<='Z') upper++;
else if (*p>='a' && *p<='z') lower++;
else if (*p>='0' && *p<='9') number++;
else if (*p==32) space++;
p++;
}
printf("upper:%d,lower:%d,number:%d,space:%d\n",upper,lower,number,space);
}
main(){
char s[]="ThE class is going,if you don't listen,you 8 may go out!";
char *p=s;
int upper=0,lower=0,number=0,space=0;
while(*p){
if (*p>='A' && *p<='Z') upper++;
else if (*p>='a' && *p<='z') lower++;
else if (*p>='0' && *p<='9') number++;
else if (*p==32) space++;
p++;
}
printf("upper:%d,lower:%d,number:%d,space:%d\n",upper,lower,number,space);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询