Saturday, February 21, 2015

Count Capital and Small Letters in C

In this article I would like to share with you a code that I wrote using C language what this program will do is to ask the user to type a word or a sentence and then our program will count the number of occurrence of capital and small letters from the word or sentence being type or provided by our user of our program.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360


Sample Output of Our Program
 
 
Program Listing
 
#include <stdio.h>

 
int main() {
   int upper = 0, lower = 0;
   char ch[80];
   int i=0;
   printf("\t Count Capital and Small Letters in C ");
   printf("\n\n");
   printf("\nEnter a sentence :=> ");
   gets(ch);

   while (ch[i] != '\0') {
        
      if (ch[i] >= 'A' && ch[i] <= 'Z')
         upper++;
      if (ch[i] >= 'a' && ch[i] <= 'z')
         lower++;
      i++;
   }

   printf("\n==============================");
   printf("\n");
   printf("======= Display Result ======= ");
   printf("\n==============================");
   printf("\n\n");
   printf("\n Number of  Uppercase Letters : %d", upper);
   printf("\n Number of Lowercase Letters : %d", lower);
   printf("\n\n");
  system("pause");
}



 

No comments:

Post a Comment