Ticker

6/recent/ticker-posts

C Language (Program to count upper, lower letter, white spaces and words)

C PROGRAM TO COUNT NUMBER OF CAPS, LOWER LETTERS, WHITE SPACES AND WORDS




#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s[60];
int L, i, sm=0, cp=0, w=1, sp=0;
puts("Enter any sentence: ");
gets(s);
L=strlen(s);

// Loop to count small and caps letters
for(i=0; i<L; i++)
{
if(s[i] >= 65 && s[i] <= 90)
{
sm = sm +1;
}

else if(s[i] >= 97 && s[i] <= 122)
{
cp = cp +1;
}

else if(s[i] == ' ')

{
sp = sp + 1;
w = w + 1;
}

// Print the final details.
printf("\nTotal number of  caps letters are: %d", cp);

printf("\nTotal number of  lower letters are: %d", sp);
printf("\nTotal number of white spaces are: %d", sp);
printf("\nTotal number words are: %d", w);
getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter any sentence:
Once Upon A Time

Total number of caps letters are: 4

Total number of lower letters are: 9
Total number of white spaces are: 3
Total number of words are: 4








MATRIX ARRAY IN C >>






Post a Comment

0 Comments