首页 > 编程语言 > 详细

1012: C语言程序设计教程(第三版)课后习题6.2

时间:2017-11-13 21:07:12      阅读:252      评论:0      收藏:0      [点我收藏+]

题目描述

输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

输入

一行字符

输出

统计值

样例输入

aklsjflj123 sadf918u324 asdf91u32oasdf/.‘;123

样例输出

23 16 2 4

 1 #include "stdio.h"
 2 
 3 int main(int argc, char const *argv[])
 4 {
 5     char s[81];
 6     int i, char_count = 0, num_count = 0, space_count = 0, other_count = 0;
 7     // scanf("%s", s);
 8     gets(s);
 9 
10     for(i = 0; s[i] != \0; i++)
11     {
12         if(s[i] >= A && s[i] <= Z || s[i] >= a && s[i] <= z)
13             char_count ++;
14         else if(s[i] >= 0 && s[i] <= 9)
15             num_count ++;
16         else if(s[i] ==  )
17             space_count ++;
18         else
19             other_count ++;
20     }
21 
22     printf("%d %d %d %d\n", char_count, num_count, space_count, other_count);
23     return 0;
24 }

 

1012: C语言程序设计教程(第三版)课后习题6.2

原文:http://www.cnblogs.com/hello-lijj/p/7827640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!