Computer Science, asked by kritvijain, 6 months ago

Write a program to input a number . Check and display whether it is a Niven number or not. (A number is said to be Niven when it is divisible by the sum of its digits.)

Sample input: 126

Sample Output: 1+2+6=9 and 126 is divisible by 9. [Niven Number or not]



please answer this question correctly or you answer it wrong u support Pakistan and China​

Answers

Answered by chintamanbhamre000
0

Answer:

(Niven number is that number which is divisible by its sum of digits). Example: Consider the number 126. The Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.

Answered by duragpalsingh
0

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