-->
Showing posts with label WAP to count total number of consonants in a sting.. Show all posts
Showing posts with label WAP to count total number of consonants in a sting.. Show all posts

WAP to count total number of consonants in a sting.

in turboc++
---------------------------------------------------------------------------------------------
//program to count total consonants in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i,total_consonants=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if((string[i]>=65 && string[i]<=90)|| (string[i]>=97 && string[i]<=122)) { if(string[i])!='a' || string[i])!='e' || string[i])!='i' || string[i])!='o' || string[i])!='u') { total_consonants++; }
    }
    printf("total consonants=%d",total_consonants);// prints total consonants.
    getch();
    return 0;
}
---------------------------------------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------------
//program to count total consonants in a string.
#include <stdio.h>
int main()
{
    char string[100],sec;
    int i,count=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
         if((string[i]>=65 && string[i]<=90)|| (string[i]>=97 && string[i]<=122)) { if(string[i])!='a' || string[i])!='e' || string[i])!='i' || string[i])!='o' || string[i])!='u') { total_consonants++; }
    }
    printf("total consonants=%d",total_consonants);// prints total consonants.
    return 0;
}