BITFRENZY

a blog dedicated to technology and programming to shape nation's future.

Breaking

Post Top Ad

Sunday, May 19, 2019

Find Digits Hackerrank Solution in c



An integer  is a divisor of an integer  if the remainder of .
Given an integer, for each digit that makes up the integer determine whether it is a divisor. Count the number of divisors occurring within the integer.
Note: Each digit is considered to be unique, so each occurrence of the same digit should be counted (e.g. for  is a divisor of  each time it occurs so the answer is ).
Function Description
Complete the findDigits function in the editor below. It should return an integer representing the number of digits of  that are divisors of .
findDigits has the following parameter(s):
  • n: an integer to analyze
Input Format
The first line is an integer, , indicating the number of test cases.
The  subsequent lines each contain an integer, .
Constraints

Output Format
For every test case, count the number of digits in  that are divisors of . Print each answer on a new line.
Sample Input
2
12
1012
Sample Output
2
3
Explanation
The number  is broken into two digits,  and . When  is divided by either of those two digits, the remainder is  so they are both divisors.
The number  is broken into four digits, , and  is evenly divisible by its digits , and , but it is not divisible by  as division by zero is undefined.

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


2 comments:

  1. this is not working for testcase 2.

    ReplyDelete
  2. ques is according to syntax it should take one input than its soultion, but it is taking all input once and returning their solution after

    ReplyDelete

Post Top Ad

Your Ad Spot

Pages