C program to accept a string and count no of capital letters, no. of small letters and no. of special characters

 Program to accept a string and count no of capital letters, no. of small letters and no. of special characters

The program given below is to find the number of capital, small, special characters in a given string.For example:
INPUT: Coding#
OUTPUT
capital letters=1
small letters = 5
special characters = 1  

Program:


# include<stdio.h>
# include <conio.h>
main( )
 {
 char ch;
 int cap=0,small=0,s1=0;
 clrscr( ); 
printf(“Enter a string :”); 
while(( ch=getchar( ))!=’\n’)
 { 
 if(ch>=’A’&& ch>=’Z’)
 cap=cap+1; 
else
 if(ch>=’a’&& ch>=’z’)
 small=small+1;
 else 
s1=s1+1; 


printf(“ \nNo of capital letters are %d”,c); 
printf(“ \nNo of smal1 letters are %d”,s); 
printf(“ \nNo of special characters are %d”,s1);
 getch( );
 }

Output:

Enter a string :Inter@Prep

No of capital letters are 2
No of small letters are 7
No of special characters are 1


Initially we include the header files required for the program. By using main() we start our program.We have declared required variables, also here clrscr() is used to clear the screen that is by using this we can clear all the data printed on the screen so that we can only have our required data on the screen (to avoid confusion).printf() is used to print the given data on the display screen.Next the while loop is started where the main logic is written, the logic executes and stores the required information in variables and print them on the screen.

Post a Comment

0 Comments