problem link:
Discuss : In this problem you can check str[i] th element in range a to z or A to Z
if it is then make word increment and flag=0 if str[i] th element not in the range then make flag again 1.
try yourself before see the code
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n,word,r;
char str[10000];
while(gets(str))
{
word=0;
n=strlen(str);
r=1;
for(i=0;i<n;i++)
{
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
{
if(r==1)
word++;
r=0;
}
else
r=1;
}
printf("%d\n",word);
}
return 0;
}
No comments:
Post a Comment