Skip to content

Instantly share code, notes, and snippets.

@kehanlu
Created October 10, 2016 13:49
Show Gist options
  • Select an option

  • Save kehanlu/e99658e17ad7b2aca95a6ee88efb82ba to your computer and use it in GitHub Desktop.

Select an option

Save kehanlu/e99658e17ad7b2aca95a6ee88efb82ba to your computer and use it in GitHub Desktop.
#include "stdio.h"
#include "string.h"
int main(){
char a[1000];
while(fgets(a,1000,stdin)!=NULL){
int space=0;
int letter =0;
if(a[0]==' ')
space--;
for(int i=0;i<strlen(a);i++){
if(a[i]==' '){
space++;
}else{
letter++;
}
}
double output = (double)(letter-1)/(space+1);
printf("Average word length: %.1f\n",output);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment