+ 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; }

28th Aug 2020, 2:42 AM
A K
A K - avatar
7 Antworten
+ 2
ᴉsɯ@ʌ🙃🙃 Thanks . It worked. But I didn't understand why u took num =1
28th Aug 2020, 7:50 AM
A K
A K - avatar
+ 2
ᴉsɯ@ʌ🙃🙃 Thanks. I got this.
28th Aug 2020, 8:05 AM
A K
A K - avatar
+ 1
This program is to find the average word length.
28th Aug 2020, 2:44 AM
A K
A K - avatar
+ 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
28th Aug 2020, 3:58 AM
A K
A K - avatar
+ 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
28th Aug 2020, 6:47 AM
v@msi😉
v@msi😉 - avatar
+ 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✌️
28th Aug 2020, 8:00 AM
v@msi😉
v@msi😉 - avatar
0
Start num=1, as you counting the spaces not words
28th Aug 2020, 3:11 AM
v@msi😉
v@msi😉 - avatar