tony


私信TA

用户名:a779610882

访问量:22845

签 名:

废物一个。

等  级
排  名 642
经  验 3918
参赛次数 1
文章发表 21
年  龄 20
在职情况 学生
学  校 大连交通大学
专  业 高达的制作和编辑

  自我简介:

别看了反正也没人看

题目分析:

     运用if作为条件筛选 

    把条件分别叠加 输出

代码:

#include <stdio.h>
int letter,digit,space,others;
int main()
{ count(char []);//调用函数声明
 char text[80];//字符串
 gets(text);//获得字符串
 letter=0;//字母
 digit=0;//数字
 space=0;//空格
 others=0;//其他
 printf("%d %d %d %d",letter,digit,space,others);
 return 0;
}
  count(char str[])
{int i;
 for (i=0;str[i]!='\0';i++)
 if ((str[i]>='a'&& str[i]<='z')||(str[i]>='A' && str[i]<='Z'))//如果是字母
    letter++;//累加
 else if (str[i]>='0' && str [i]<='9')//如果是数字
    digit++;//累加
 else if (str[i]==32)//如果是空格
    space++;//累加
 else
    others++;//其他累加
}


 

0.0分

0 人评分

  评论区