Ticker

6/recent/ticker-posts

C Language (Program to count vowels and consonants in a string)

C PROGRAM TO COUNT VOWELS IN A STRING





#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s[60];
int L, i, v=0;
puts("Enter any sentence: ");
gets(s);
L=strlen(s);

// Loop to find vowels in the given string
for(i=0; i<L; i++)
{
switch(s[i])
{
case 'a';   case'A';


case 'e':   case 'E':
case 'i':    case 'I':
case 'o':   case 'O':
case 'u':   case 'U':
v++;
}
}
printf("\nTotal vowels are : %d", v);
getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter any sentence:
Once upon a time

Total number of vowels: 7








C PROGRAM TO COUNT VOWELS AND CONSONANT IN A STRING


#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s[60];
int L, i, v=0, c=0;
puts("Enter any sentence: ");
gets(s);
L=strlen(s);

// Loop to count total number of vowels and consonants
for(i=0; i<L; i++)
{
if (s[i]=='a' || s[i]=='A' || s[i]=='e' || s[i]=='E' || s[i]=='i' || s[i]=='I' || s[i]=='o' || s[i]=='O' || s[i]=='u' || s[i]=='U')
{
v=v+1;
}

else if (s[i] == ' ')
{
}

else
{
c=c+1;
}
}

printf("\nTotal vowels are : %d", v);
printf("\nTotal consonants are : %d", c);
getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter any sentence:
Once upon a time

Total vowels are: 7
Total consonants are: 6
















Post a Comment

0 Comments