HackerRank 'Find Digits' Solution

by Srikant Padala on June 25, 2016, 4:38 am


Explanation


check for this condition [r != 0 && (n % r == 0)], where r is the rightmost digit and n is the input number itself


Find Digits Problem Statement

Video

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

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

Coming Soon.