Find Digits - HackerRank || HackerRank Find Digits Solution

Problem Name: Find Digits
Judge: HackerRank
Problem link: Find Digits



HackerRank Find Digits Solution in C

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int number, count = 0, rest, temp;
        scanf("%d", &number);
        temp = number;
        while (temp != 0)
        {
            rest = temp % 10;
            if (rest != 0 && number % rest == 0) count++;
            temp = temp / 10;
        }
        printf("%d\n", count);
    }
    return 0;
}


HackerRank Find Digits Solution in C++/Cpp

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int number, rest, temp, count = 0;
        cin >> number;
        temp = number;
        while (temp != 0)
        {
            rest = temp % 10;
            if (rest != 0 && number % rest == 0) count++;
            temp = temp / 10;
        }
        cout << count << endl;
    }
    return 0;
}


HackerRank Find Digits Solution in Java

import java.util.Scanner;

public class Find_Digits {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 1; i <= n; i++) {
            int number = input.nextInt();
            int temp = number;
            int rest, count = 0;
            while (temp != 0) {
                rest = temp % 10;
                if (rest != 0 && number % rest == 0) count++;
                temp = temp / 10;
            }
            System.out.println(count);
        }
    }
}





Next Post Previous Post
No Comment
Add Comment
comment url