+ 2
Can anyone help me with this code?
#include <stdio.h> #include <string.h> #include <ctype.h> int main() { char string[50]; int i,l; float avg ; int count = 0,num=0; scanf("%[^\n]s",string ); l= strlen(string); for(i=0;i<l;i++) { if (isalpha(string[i])) count += 1; else if (string[i] == ' '&& string[i+1]!= ' ') { num += 1; } } avg = (count/num); printf("%1.0f",avg); return 0; }
7 Antworten
+ 2
ᴉsɯ@ʌ🙃🙃
Thanks . It worked. But I didn't understand why u took num =1
+ 2
ᴉsɯ@ʌ🙃🙃
Thanks. I got this.
+ 1
This program is to find the average word length.
+ 1
ᴉsɯ@ʌ🙃🙃
I don't think anything's wrong with formula. It's a code coach problem and it didn't pass the last three tests
+ 1
A K formula is correct but you shd round the value and start num with 1
Here you can refer
https://code.sololearn.com/cyGj9UX9jPXh/?ref=app
+ 1
You need no of words, so
Here's the example
hey hi hello(3 words 2 spaces)
as you are counting spaces it shd be added with 1 to get words count.
If still not get the point dm me✌️
0
Start num=1, as you counting the spaces not words