您的位置:首页 > 其它

编写一个程序 把输入作为字符流读取 直到遇到EOF 报告单词的平均字母数(图)

2012-05-07 20:52 477 查看
#include "stdAfx.h"
#include "ctype.h"
#include "stdlib.h"

int main(void)
{
int ch,i=0,j=0;
float sum;

printf("Please enter a word the inspection of the average number of letters and words several letters\n");
printf("After input press CTRL + Z to calculate\n:");

while((ch=getchar())!=EOF)
{
if(ch>='A'&&ch<='z'||ch>='A'&&ch<='Z')
i++;
else if(ch==32)
j++;
}

sum=i/(j+1);
printf("Letters have %d\naverage number of letters have %0.2f\n",i,sum);

system("pause");

return 0;
}

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