Sum of Digits Multiple
PROBLEM :
Check that the sum of Digits is multiple of number or not.
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 Yes if multiple else No
Constraints:
1 = T = 50
1 = N = 100000
Example:
Input
2
18
99270
Output
Yes
No
Explanation:
1. sum of digit is 9 which is multiple of 18
2. sum of digits is 27 which is not a multiple of 99270
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int t,no,org,sum,rem ;
cin>>t ;
while(t--)
{
cin>>no ;
org=no ;
sum=0 ;
while(no!=0)
{
rem=no%10 ;
sum=sum+rem ;
no=no/10 ;
}
if(org%sum==0)
cout<<"Yes" ;
else
cout<<"No" ;
cout<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Check that the sum of Digits is multiple of number or not.
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 Yes if multiple else No
Constraints:
1 = T = 50
1 = N = 100000
Example:
Input
2
18
99270
Output
Yes
No
Explanation:
1. sum of digit is 9 which is multiple of 18
2. sum of digits is 27 which is not a multiple of 99270
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int t,no,org,sum,rem ;
cin>>t ;
while(t--)
{
cin>>no ;
org=no ;
sum=0 ;
while(no!=0)
{
rem=no%10 ;
sum=sum+rem ;
no=no/10 ;
}
if(org%sum==0)
cout<<"Yes" ;
else
cout<<"No" ;
cout<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Comments
Post a Comment