top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Find the Digits that can divide the number N

+5 votes
457 views

Given an integer N, traverse it's digits {d1,d2,d3,d4.....dn} and find out how many of them evenly dived the number N?
for example:1012 ,digits 1, 1 and 2 evenly divide 1012 while 0 does not
so the output is =3

posted Mar 31, 2016 by Shahsikant Dwivedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Try this c++14 code and link below for compiled code where I tested this with some custom inputs:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int number,numberDigit,newnumber,countD,Orinumber,test;
    scanf("%d",&test);
    while(test--){
    scanf("%d",&number);
    Orinumber=number;
    countD=0;
    while(number){

           numberDigit=number%10;
           number=number/10;
           if(numberDigit==0){
            continue;
           }
           else{
            if((Orinumber%numberDigit)==0){
            countD++;
           }
       }
    }
    printf("%d\n",countD);
    }
    return 0;
}

Compile Online:
https://ideone.com/ba9oPD

answer Apr 1, 2016 by Shivam Kumar Pandey
worked perfectly thanks shivam.
Similar Questions
0 votes

You are given 2 long integers having n digits each and you are required to multiply them using C.

Assumptions
Numbers are represented in an array of size n .
Calculate the time complexity using traditional divide and conquer

0 votes

Alex has been asked by his teacher to do an assignment on sums of digits of a number. The assignment requires Alex to find the sum of sums of digits of a given number, as per the method mentioned below.

If the given number is 582109, the Sum of Sums of Digits will be calculated as =
= (5 + 8 + 2 + 1 + 0 + 9) + (8 + 2 + 1 + 0 + 9) + (2 + 1 + 0 + 9) + (1 + 0 + 9) + (0 + 9) + (9)
= 25 + 20 + 12 + 10 + 9 + 9 = 85

Alex contacts you to help him write a program for finding the Sum of Sums of Digits for any given number, using the above method.

Help Alex by completing the login in the given function sumOfSumsOfDigits which takes as input an integer input1 representing the given number.
The function is expected to return the "Sum of Sums of Digits" of input1.

Assumptions: For this assignment, let us assume that the given number will always contain more than 1 digit, i.e. the given number will always be >9.

...