-->
Showing posts with label WAP to count total digits present in a string.. Show all posts
Showing posts with label WAP to count total digits present in a string.. Show all posts

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