Thursday, 9 February 2017

Find Digits

Find Digits


Given an integer, , traverse its digits (1,2,...,n) and determine how many digits evenly divide  (i.e.: count the number of times  divided by each digit i has a remainder of ). Print the number of evenly divisible digits.
Note: Each digit is considered to be unique, so each occurrence of the same evenly divisible digit should be counted (i.e.: for , the answer is ).
Solution---

#include<stdio.h>
int main()
{
        int t,i,a,d,c,count,j;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {       count=0;
                scanf("%d",&a);
                c=a;
                while(a!=0){
                d=a%10;
                a=a/10;
                
             if(d!=0 && c%d==0)
                        count++;
                              
               
                }
                printf("%d\n",count);
        }
return 0;
}

No comments:

Post a Comment