C语言编程题:从键盘输入一串字符,统计其中的数字与字母个数并输出。(用指针实现)

 我来答
匿名用户
推荐于2018-03-13
展开全部
#include<stdio.h>
int j=0,k=0,l=0;
int main()
{char a[100],*p;
void can(char *p);
printf("输入一个字符串");
p=a;
gets(a);
can(p);
printf("大写字母%d个\n",j);
printf("小写字母%d个\n",k);
printf("数字%d个\n",l);return 0;}
void can(char *p)
{for(;*p;p++)
if((*p>='a')&&(*p<='z'))
++k;
else if((*p>='A')&&(*p<='Z'))
++j;
else if((*p>='0')&&(*p<='9'))
++l;
}
liubird
2011-12-24 · TA获得超过1931个赞
知道小有建树答主
回答量:898
采纳率:100%
帮助的人:909万
展开全部
#include <stdio.h>
int main()
{
int n, t, n1=0, n2=0;
char str[1001], *p;

printf("请输入一个字符串: ");
gets(str);
p = str;
while (*p!='\0') {
if(*p>='0' && *p<='9') n1 ++;
else if (*p>='a' && *p<='z' || *p>='A' && *p<='Z') n2 ++;
p ++;
}
printf("其中数字有%d个, 字母有%d个\n",n1, n2);
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
c001848
2011-12-24 · TA获得超过537个赞
知道小有建树答主
回答量:470
采纳率:0%
帮助的人:194万
展开全部
#include<stdio.h>
#include<string.h>

void main()
{
char ch[128];
int alpha = 0, num = 0, spc = 0, oth = 0;
int i = 0;

printf("请输入字符串: ");
while ((ch[i++] = getchar()) != '\n');

for (i = 0; i < strlen(ch); i++)
{
if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z'))
alpha++;
else if (ch[i] >= '0' && ch[i] <= '9') num++;
else if (ch[i] == 32) spc++;
else oth++;
}
printf("字母: %d, 数字: %d, 空格: %d, 其他: %d\n", alpha, num, spc, oth);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
五五开Fl
2011-12-28 · 超过18用户采纳过TA的回答
知道答主
回答量:180
采纳率:0%
帮助的人:50.8万
展开全部
#include<stdio.h>
int main()
{
char c;
int word=0,number=0,gap=0,other=0;
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')
word++;
else if(c>='0'&&c<='9')
number++;
else if(c==' ')
gap++;
else
other++;
}
printf("word:%d\tnumber:%d\tgap:%d\tother:%d\n",word,number,gap,other);
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式