**有一个三行每行80个字符的小短文,统计出短文中大写字母,小写字母,数字,空格和其他字符的个数**

分析一些题目可知,我们可以用两个for循环嵌套起来遍历每行的文字,然后用if语句对每一个文字进行判断,然后给相应的文字类型++,最后输出。

#include "stdafx.h"
#include"stdlib.h"
int judge(int cap, int low, int digit,int blank, int other);
char easy[3][80];
int main()
{   int cap,low,digit,blank,other;
 cap = low = digit = blank = other = 0;
 judge(cap, low, digit, blank, other);
 system("pause");
 return 0;}
int judge(int cap, int low,int digit, int blank, int other)
{   int i, j;
 cap = low =digit= blank = other = 0;
 for (i = 0; i < 3; i++)
 {   printf("input text of this trip\n");
  gets_s(easy[i]);
  for (j = 0; j < 80 && easy[i][j] != '\0'; j++)
  {if (easy[i][j] >= 'A'&&easy[i][j] <= 'Z')//判断是否为大写字母
    cap++;
   else if (easy[i][j] >= 'a'&&easy[i][j] <= 'z')
    low++;
   else if (easy[i][j] >= '0'&&easy[i][j] <= '9')
    digit++;
   else if (easy[i][j] == ' ')
    blank++;
   else  other++;}}
 printf("大写字母有%d个\n", cap);
 printf("小写字母有%d个\n", low);
 printf("数字有%d个\n", digit);
 printf("空格有%d个\n", blank);
 printf("其他字符有%d个\n", other);
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值