题目:编写一个程序。该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及所有其他字符数目。
//7-1
#include<stdio.h>
int main(void)
{
char ch;
int space,rows,other;
space=rows=other=0;
while((ch=getchar())!='#'){
if (ch==' '){
space++;
}
else if(ch=='\n'){
rows++;
}
else
other++;
}
printf("空格数有%d个,换行数有%d个,其他字符有%d个。\n",space,rows,other);
return 0;
}

本文介绍了一个简单的C语言程序,该程序能够读取用户输入直至遇到特定字符'#'为止,并统计并输出空格、换行符以及其他字符的数量。
1959

被折叠的 条评论
为什么被折叠?



