码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-11-13 21:18:35      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:++   个数   第三版   输出   字母   const   c语言程序   ace   get   

题目描述

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

输入

一行字符

输出

统计值

样例输入

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

标签:++   个数   第三版   输出   字母   const   c语言程序   ace   get   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!