TechoSagar: Sum of Digits Divisibility Show Topic Tags

Search

Google Alert - jobs

Sum of Digits Divisibility Show Topic Tags

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
Your Code
#include<iostream>

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x=n;
int sum=0;
while(n!=0)
{
sum=sum+n%10;
n=n/10;
}
if(x%sum==0)
{
cout<<"1"<<endl;
}
else
cout<<"0"<<endl;
}
return 0;
}

Follow us

Follow Bijendra Kumar on Facebook