google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to count the number of vowels and consonants in a string - 2nd puc computer science

Write a program to count the number of vowels and consonants in a string

// Write a program to count the number of vowels and consonants in a string

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<ctype.h>

void main()

{

char s[100];

int l,i,cons=0,vow=0;

clrscr();

cout<<"Enter the string: ";

cin.getline(s,100);

l=strlen(s);

for(i=0;i<l;i++)

if(isalpha(s[i]))

switch(toupper(s[i]))

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U': vow++;

              break;

default: cons++;

}

cout<<"Number of vowels: "<<vow<<endl;

cout<<"Number of consonants: "<<cons<<endl;

getch();

}

Write a program to count the number of vowels and consonants in a string Write a program to count the number of vowels and consonants in a string Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.