Wednesday, 28 August 2013

WAP to count the occurrences of a digit in a number.

#include<stdio.h>
void main()
{
    int num, m, rem, count=0,n;
    printf("Enter Number: ");
    scanf("%d", &num);
    printf("enter the number which has to be checked:");
    scanf("%d",&m);
    while(num!=0)
        {
        rem=num%10;
        num=num/10;
        if(m==rem)
        count++;
        }
    printf("\n%d is present %d times", m, count);
}

No comments:

Post a Comment