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;
}
---------------------------------------------------------------------------------
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
Post a Comment