Write a program to accept a number and check
and display wheather it is a Niven number
or not.
Answers
Answered by
1
Answer:
the accepting and number is Control + C with it will copy then it will be accepted 11 number in or not there is can be 11 numbers and can be divided
Answered by
5
Question:
Write a program to input an integer and check whether it is Harshad or Niven number or not. A number is said to be Harshad if it is divisible by the sum of the digits of that number, example 126 and 1729.
Solution:
Language used: Java
import java.util.*;
public class NivenNo
{
static void main()
{
Scanner sc=new Scanner(System.in);
int d,s=0,n,t;
System.out.println("Enter an integer:");
n=sc.nextInt();
t=n;
while(t!=0)
{
d=t%10;
s=s+d;
t=t/10;
}
if(n%s==0)
System.out.println("Harshad Number");
else
System.out.println("Not a Harshad Number");
}
}
Similar questions