Hackerrank

HackerRank Solution of Data Structure .I Will Try to Post very Question Solution that will help you to improve coding skill.For any query you can Ask me.

HackerRank Solution– Find Digits

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

123
2121012

Sample Output

12
23

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 <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
 
int main()
{
    int a0,t,p;
    scanf("%d",&t);
    for(a0 = 0; a0 < t; a0++)
    {
        int n,t,d;
        p = 0;
        scanf("%d",&n);
        t=n;
        while(n>0)
        {
         d=n%10;
         if (d!=0)
            if(t%d==0)
                    p++;
         n/=10;
        }
        printf("%d\n",p);
    }
    return 0;
}

If you’re a college student and have skills in programming languages, Want to earn through blogging? Mail us at geekycomail@gmail.com

For more Programming related blogs Visit Us Geekycodes . Follow us on Instagram.

Leave a Reply