C program read a sentence and count the number of number of vowels and consonants in the given sentence. Output the results on two lines with suitable headings

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program read a sentence and count the number of number of vowels and consonants in the given sentence. Output the results on two lines with suitable headings */

#include <stdio.h>
#include <conio.h>

void main()
{
char sentence[80];
int i, vowels=0, consonants=0, special = 0;

clrscr();

printf(“Enter a sentence\n”);
gets(sentence);

for(i=0; sentence[i] != ‘\0′; i++)
{
if((sentence[i] == ‘a’||sentence[i] == ‘e’||sentence[i] == ‘i’||
sentence[i] == ‘o’||sentence[i] == ‘u’) ||(sentence[i] == ‘A’||
sentence[i] == ‘E’||sentence[i] == ‘I’|| sentence[i] == ‘O’||
sentence[i] == ‘U’))
{
vowels = vowels + 1;
}
else
{
consonants = consonants + 1;
}
if (sentence[i] ==’\t’ ||sentence[i] ==’\0′ || sentence[i] ==’ ‘)
{
special = special + 1;
}
}

consonants = consonants – special;
printf(“No. of vowels in %s = %d\n”, sentence, vowels);
printf(“No. of consonants in %s = %d\n”, sentence, consonants);

}
/*—————————————-
Output
Enter a sentence
Good Morning
No. of vowels in Good Morning = 4
No. of consonants in Good Morning = 7
—————————————–*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to enter a sentence and output the number of uppercase & lowercase consonants, uppercase & lowercase vowels in sentence..
  2. C program to read an English sentence and replace lowercase characters by uppercase and vice-versa. Output the given sentence as well as the case converted sentence on two different lines.
  3. C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
  4. Sample – Program to count the number of words and characters in a sentence.
  5. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings

Leave a Comment

Previous post:

Next post: