C program to count and print the number of vowels,consonant, digits and special character.
In this tutorial we will learn how to write a c program to find the numbers of vowels,digits,consonants and special character in a given string or sentence.
In the first user will enter a string or a statement in which all(vowels,consonant, digits and symbols) are available then the compiler count the numbers of vowels, consonant, digits and special characters.
In this tutorial we will learn how to write a c program to find the numbers of vowels,digits,consonants and special character in a given string or sentence.
In the first user will enter a string or a statement in which all(vowels,consonant, digits and symbols) are available then the compiler count the numbers of vowels, consonant, digits and special characters.
C program source code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,vowel=0,consonant=0,special=0,letters=0,digits=0;
char str[100];
clrscr();
printf("\n ENTER A STRING OR A MIX SENTENCE:\n ");
printf("\n ");
gets(str);
printf("\n ");
for(i=0;i<strlen(str);i++)
{
if(str[i]=='A'||str[i]=='a'||str[i]=='E'||str[i]=='e'||
str[i]=='I'||str[i]=='i'||str[i]=='O'||str[i]=='o'||str[i]=='U'||str[i]=='u')
{
vowel++;
}
else if(str[i]>=0&&str[i]<=47||str[i]>=58&&str[i]<=64||
str[i]>=91&&str[i]<=96||str[i]>=123&&str[i]<=127)
{
special++;
}
else if(str[i]>'0'&&str[i]<'9')
{
digits++;
}
}
printf("\n NUMBER OF VOWELS IS:%d\n ",vowel);
printf("\n NUMBER OF CONSONANT IS:%d\n ",strlen(str)-vowel-special-digits);
printf("\n NUMBER OF DIGITS IS:%d\n ",digits);
printf("\n NUMBER OF SPECIAL CHARACTERS IS:=%d\n ",special);
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment