Write java program for the following [12]
1. A number is said to be Ragas number if the number is exactly divisible by
the sum of its digits. For example 1729 because sum of the digits of 1729 is
1+7+2+9 = 19 and 1729 is exactly divisible by 19. Write a program to
input a number and print whether it is Ragas number or not. Give proper
messages for your output.
Answers
Answered by
6
Answer:
import java.util.*;
class Ragas{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
for(int N1=n,s=0;N1!=0;N1/=10)
s+=N1%10;
if(n%s==0)
System.out.println(n+" is a Ragas Number");
else
System.out.println(n+" is not a Ragas Number");
}
}
- Required Output Attached ♪♪
Attachments:
Answered by
0
Answer:
Input: N = 12
Output: YES
Explanation:
As sum of digits of 12 = 1 + 2 = 3
and 12 is divisible by 3
So the output is YES
Input: N = 123
Output: NO
Similar questions