Author Topic: Turbo C program to count number of alphabets and non-alphabets in a string  (Read 1419 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Here is the Turbo C program to count number of alphabets and non-alphabets in a string

Code:
//Source Code Listing

#include <stdio.h>
#include <string.h>

void main()
{
   char input[128];
   int i = 0;
   int alphabet_count = 0;
   int non_alphabet_count = 0;
   int length = 0;

   printf("Program to count the number of alphabets and non-alphabets\n");
   printf("Enter a string:");
   gets(input);
   length = strlen(input);

   for(i = 0; i < length; i++)
   {
      if(input[i] >= 'a' && input[i] <= 'z')
         alphabet_count++;
      else if(input[i] >= 'A' && input[i] <= 'Z')
         alphabet_count++;
      else 
         non_alphabet_count++;

   }

   printf("Number of alphabets: %d\n", alphabet_count);
   printf("Number of Non-alphabets: %d\n\n", non_alphabet_count);
   getch();
}




output:

Program to count the number of alphabets and non-alphabets
Enter a string:welcome to software & finance
Number of alphabets: 24
Number of Non-alphabets: 5



 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1