Sum of Digits Divisibility

PROBLEM :

Check that the number can be divided by the sum of its digit.

Input:

The first line of input contains an integer T denoting the number of test cases.Then T test cases follow .Each test case consist of an integer N.

Output:

Print 1 if divisible else 0.

Constraints:

1 = T = 100
1 = N = 100000

Example:

Input
2
18
19170

Output
1
1
     
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
int main()
 {
int t,rem,sum ;
long no,org ;
cin>>t ;
while(t--)
{
   cin>>no ;
 
   sum=0 ;
   org=no ;
 
   while(no!=0)
   {
       rem=no%10 ;
       sum=sum+rem ;
       no=no/10 ;
   }
 
   if(org%sum==0)
       cout<<1 ;
   else
       cout<<0 ;
   cout<<endl ;
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )