您的位置:首页 > 编程语言 > C语言/C++

C语言编程(练习2:分支和跳转 )

2015-01-06 15:44 246 查看
题目: 编写一个程序。该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及读取的所有其他字符数目。

/**< 该程序读取输入直到遇到#字符,然后报告读取的空格数目、
读取的换行符数目以及读取的所有其他字符数目 */
#include <stdio.h>
#include <stdlib.h>

int main()
{
int blank = 0;
int newline = 0;
int others = 0;
char c;
while((c = getchar()) != '#')
{
if(c == ' ')
{
blank++;
}
else if(c == '\n')
{
newline++;
}
else others++;
}
printf("blank=%d, newline=%d, others=%d\n",blank, newline, others);
return 0;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: