Friday, June 28, 2019

Harshad Number | Programming | Eclipse JAVA | Follow on Youtube for more






import java.util.*;
// Harshad number is also called niven number
public class harshad_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked");
int n  = sc.nextInt();
int n1 = n;
int sum = 0;
while(n1!=0)
{
int rem  = n1%10;
sum  = sum + rem;
n1 = n1/10;
}
if(n%sum==0)
{
System.out.println(n+" is a harshad number");
}
else
{
System.out.println(n+" is not a harshad number");
}
}
}
/*
Input: 3
Output: 3 is a Harshad Number

Input: 18
Output: 18 is a Harshad Number

Input: 15   
Output: 15 is not a Harshad Number


54       9
*/

No comments:

Post a Comment

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...