Count number of letters and words present in string
The following program takes a string as input and prints number of letters and number of words present in the string. The following code is implemented using c.
Code:
#include<stdio.h>
#include<string.h>
int main()
{
int c=0,c1=0,i;
char str[30];
printf("Enter a sentence : \n");
gets(str);
for(i=0;str[i]!='\0';i++)
{
c++;
if(str[i]==' ')
c1++;
}
printf("\nNumber of letters present : %d",c);
printf("\nNumber of words present : %d",c1+1);
return 0;
}

Comments
Post a Comment