Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 20161009平均字元長度.cpp : 定義主控台應用程式的進入點。
- //
- #include "stdio.h"
- int main()
- {
- char a[100] = { '\0' };
- while (gets(a) != EOF)
- {
- float character = 0;
- float space = 1;
- int i=0;
- while (a[i] == ' ')
- {
- i++;
- }
- for (i; a[i]!='\0'; i++)
- {
- if (a[i] == ' ')
- {
- space++;
- i++;
- while (a[i] == ' ')
- {
- i++;
- }
- if (a[i] == '\0')
- {
- space--;
- break;
- }
- }
- if (a[i] != '\0'&&a[i] != ' ')
- character++;
- }
- printf("Average word length: ");
- printf("%.1f\n",character / space);
- char a[100] = { '\0' };
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment