+ 3
This is a code in C to find the average word length but it does not work beyond case 1.......why?
#include <stdio.h> #include<string.h> int main() { int l,s; char a[100]={0}; fgets(a,100,stdin); for(int i=0;i<98;++i) { if((a[i]<=90 && 65<=a[i]) || (a[i]<=122 && a[i]>=97)) { l++; } } for(int i=0;i<98;++i) { if(a[i]==' ') { s++; } } float c; c=(l/(s+1))+0.5; int d; d=c; printf("%d",d); return 0; }
2 odpowiedzi
+ 3
Round up means 3.000000000001 becomes 4 or ceiling. Your code is doing a normal round. Use ceil for it.
https://www.programiz.com/cpp-programming/library-function/cmath/ceil
+ 2
Thank you.I think I misunderstood the question.