发布一个关于求句子平均词长的小程序
#include<stdio.h>#define N 80
int main()
{
char ch,a[N]={'\0'};
int i=0,n=0,m=0,j=1;
printf("Enter a sentence:");
ch=getchar();
while(ch!='\n')
{
a[i++]=ch;
ch=getchar();
}
a[i]='\0';
for(n=0;n<i;n++)
{
if(a[n]==' ')
{
j++;
continue;
}
m++;
}
printf("Averge word length:%.1f\n",(float)m/j);
//getchar();
return 0;
}