-->

Tuesday, December 17, 2019

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;
}


Monday, December 16, 2019

WAP to count total number of vowels in a string.

in turboc++
--------------------------------------------------------------------------------------
//program to count total vowels in a string.
#include <stdio.h>
#include<string.h>
#include<conio.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]=='a' || string[i]=='e'|| string[i]=='i'|| string[i]=='o' ||string[i]=='u')
                                            //condition testing for character/vowels
        {
            count++;//counting  words
        }
    }
    printf("total vowels=%d",count);// prints total vowels.
    getch();
    return 0;
}

----------------------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------------------------------------------------------
//program to count total vowels in a string.
#include <stdio.h>
#include<string.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]=='a' || string[i]=='e'|| string[i]=='i'|| string[i]=='o' ||string[i]=='u')
                                            //condition testing for character/vowels
        {
            count++;//counting  words
        }
    }
    printf("total vowels=%d",count);// prints total vowels.
    return 0;
}


WAP to count total words in a string.

in turboc++
-------------------------------------------------------------
//program to count total words in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i,count=1;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==' ')//condition testing for character
        {
            count++;//counting  words
        }
    }
    printf("total words=%d",count);// prints total words.
    getch();
    return 0;
}
---------------------------------------------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------------------------------------------------------
//program to count total words in a string.
#include <stdio.h>
int main()
{
    char string[100],sec;
    int i,count=1;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==' ')//condition testing for character
        {
            count++;//counting  words
        }
    }
    printf("total words=%d",count);// prints total words.
    return 0;
}

WAP to count particular character in a string.

in turboc++
--------------------------------------------------------------------------------------
//program to count a particular character in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i,count=0;
    printf("enter string\n");
    gets(string);//accepts string
    printf("enter a character\n");
    sec=getchar();//accepts a character
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==sec)//condition testing for character
        {
            count++;//counting  character
        }
    }
    printf("total character=%d",count);// prints total character.
    getch();
    return 0;
}
-----------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to count a particular character in a string.
#include <stdio.h>
int main()
{
    char string[100],sec;
    int i,count=0;
    printf("enter string\n");
    gets(string);//accepts string
    printf("enter a character\n");
    sec=getchar();//accepts a character
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==sec)//condition testing for character
        {
            count++;//counting  character
        }
    }
    printf("total character=%d",count);// prints total character.
    
    return 0;
}

WAP to count total spaces in a string.

in turboc++
-------------------------------------------------------------------
//program to count total spaces in a string.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char string[100];
    int i,count=0;
    printf("enter first string\n");
    gets(string);//accepts string
      for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]>=' ' )//condition testing for white space
        {
            count++;//increment in count.
        }
    }
    printf("total spaces=%d",count);// prints the total value.
         getch();
        return 0;
}
--------------------------------------------------------------------------------------------------
in codeblocks:
--------------------------------------------------------------------------------------------------------------------
//program to count total spaces in a string.
#include <stdio.h>
#include<string.h>
int main()
{
    char string[100];
    int i,count=0;
    printf("enter first string\n");
    gets(string);//accepts string
      for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]>=' ' )//condition testing for white space
        {
            count++;//increment in count.
        }
    }
    printf("total spaces=%d",count);// prints the total value.
     
        return 0;
}

Sunday, December 15, 2019

WAP to count total digits present in a string.

in turboc++
---------------------------------------------------------------------------
//program to count total digits in a string.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char string[100];
    int i,count=0;
    printf("enter first string\n");
    gets(string);//accepts string
      for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]>='0' && string[i]<='9')//condition testing for white space
        {
            count++;//increment in count.
        }
    }
    printf("total digits=%d",count);// prints the total value.
    getch();
    return 0;
}
---------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------
//program to count total digits in a string.
#include <stdio.h>
#include<string.h>
int main()
{
    char string[100];
    int i,count=0;
    printf("enter first string\n");
    gets(string);//accepts string
      for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]>='0' && string[i]<='9')//condition testing for white space
        {
            count++;//increment in count.
        }
    }
    printf("total digits=%d",count);// prints the total value.
        return 0;
}

WAP to replace all white spaces with a character.

in turboc++
---------------------------------------------------------------------------------
//program to replace all white space with a character.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i;
    printf("enter first string\n");
    gets(string);//accepts string
    printf("enter a character\n");
    sec=getchar();//accpts a character
    printf("before replacing,string is %s\n",string);
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==' ')//condition testing for white space
        {
            string[i]=sec;//assigning character
        }
    }
    printf("after replacing, the string=%s",string); //prints the string.
  getch(); 
  return 0;
}
----------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------
//program to replace all white space with a character.
#include <stdio.h>
#include<string.h>
int main()
{
    char string[100],sec;
    int i;
    printf("enter first string\n");
    gets(string);//accepts string
    printf("enter a character\n");
    sec=getchar();//accpts a character
    printf("before replacing,string is %s\n",string);
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]==' ')//condition testing for white space
        {
            string[i]=sec;//assigning character
        }
    }
    printf("after replacing, the string=%s",string); prints the string.
    return 0;
}