C Program to count number of sentences words and letters in a paragraph

How to write a C Program to count number of sentences words and letters in a paragraph in C Programming Language ?

This C Program to count number of sentences words and letters in a paragraph.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4.         char ch[150];
  5.         int i,c=0,c1=0,c2=0;
  6.         printf("Enter a Paragraph \n");
  7.         gets(ch);
  8.         for(i=0;ch[i]!='\0';i++)
  9.         {
  10.                 if(ch[i]=='.'||ch[i]=='!'||ch[i]=='?')
  11.                 {       c++;
  12.                         c1++;
  13.                 }
  14.                 else if(ch[i]==' '||ch[i]==',')
  15.                         c1++;
  16.                 else if(ch[i]>65&&ch[i]<123)
  17.                         c2++;
  18.         }
  19.         printf("\nNumber of letters = %d \nNumber of words=%d ",c2,c1);
  20.         printf("\nNumber of Sentences = %d\n",c);
  21. }


Learn More :