Write a program to accept a no. and check whether it is a Niven no. or not. Niven no. is that no. which is divisible by the sum of its digits.
Eg- 126 as 1+2+6=9 and 126 is divisible by 9
Answers
Answered by
42
Attachments:
Answered by
61
import java.util.*;
class niven_number
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number to check whether it is a niven number or not");
int n=sc.nextInt();
int d=0;
int s=0;
int cpy=n;
while(n>0)
{
d=n%10;
s=s+d;
n=n/10;
}
if(cpy%s==0)
{
System.out.println(cpy+" is a niven number");
}
else
{
System.out.println(cpy+" is not a niven number");
}
}
}
Similar questions