Niven number is a number which is
divisible by the sum of its digits.
Example : N = 16
, s = 1+6 = 7 ; n%s != 0 ; so it
is Not a Niven number.
N = 12 , s = 1+2 = 3 : n%s ==0 : so it is Niven number
import java.util.* ;
class Niven
{
public static void
main(String[] args)
{
int rem ;
int s = 0;
Scanner sk = new
Scanner(System.in);
System.out.print("Enter number: ");
int n = sk.nextInt();
int temp = n ;
while (n != 0)
{
rem = n%10;
s = s + rem;
n = n/10;
}
if(temp % s == 0)
{
System.out.println(" Niven number ");
}
else
{
System.out.println(" Not a Niven number ");
}
}
}
Search my New YouTube channel : SK Skill India
Sukriya......
ReplyDeleteshashikant
Thank u sir Afroz
ReplyDelete