Posted By:
23 Jun, 2013 1:11 pm PDT

Strings in C

How can you find the consonants in a given string?
Attachment:None


To find the number of consonants we first have to count the number of characters in the whole String, then calculate the number of vowels and then subtract the vowels from the total number of characters. We can use the code to find the no of consonants

l=strlen(a);

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

{   

    if(a[i]=='a' || a[i]=='e' || a[i]=='o' || a[i]=='i' || a[i]=='u')

        c++;

   

}

p=l-c;

printf("\n\n\n\t\t------------OUTPUT------------");

printf("\n\nthe total no. of consonants in the string are=%d",p);

getch();

 

 Please see the video for more details�

Was it useful?  



The above solution is simple and easy . Just to make it more effective , i added some extra kilo bytes of data .

l=strlen(a);

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

{   

    if(a[i]=='a' || a[i]=='e' || a[i]=='o' || a[i]=='i' || a[i]=='u' || a[i]="A" || a[i]="E" || a[i]="I" || a[i]="O" || a[i]="U")

        c++;

   

}

p=l-c;

printf("\n\n\n\t\t------------OUTPUT------------");

printf("\n\nthe total no. of consonants in the string are=%d",p);

getch();

 

Now irrespective of the Cases of String , we will get the correct output.

 


Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud