# Check whether a given number is a Harshad number or not

Write a C program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not in C.

Program in C

Code:

/*Write a C program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not Using C*/

#include<stdio.h>
int main()
{
int num;
printf("Enter a number:");
scanf("%d",&num);
int num2=num;
int sum=0;
while(num!=0)
{
int rem=num%10;
num=num/10;
sum=sum+rem;
}
if(num2%sum==0)
else
printf("It is not a Harshad Number");
}

Input/Output:
Enter a number:21

Write a C++ program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not in C++.

Program in C++

Code:

/*Write a C++ program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not using C++*/

#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:";
cin>>num;
int num2=num;
int sum=0;
while(num!=0)
{
int rem=num%10;
num=num/10;
sum=sum+rem;
}
if(num2%sum==0)
else
cout<<"It is not a Harshad Number";
}

Input/Output:
Enter a number:7

Write a JAVA program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not in Java.

Program in Java

Code:

/*Write a JAVA program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not using Java*/

import java.util.Scanner;

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
System.out.println("Enter a number:");
num=cs.nextInt();
int num2=num;
int sum=0;
while(num!=0)
{
int rem=num%10;
num=num/10;
sum=sum+rem;
}
if(num2%sum==0)
else
System.out.println("It is not a Harshad Number");
cs.close();
}
}

Input/Output:
Enter a number:
55
It is not a Harshad Number

Write a PYTHON to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not in Python.

Program in Python

Code:

'''Write a Python program to check whether a given number is a Harshad number or not. or Write a program to check whether a given number is a Harshad number or not using Python '''

num=int(input("Enter a number:"))
num2=num
sum=0
while num!=0:
rem=num%10
num=int(num/10)
sum=sum+rem
if(num2%sum==0):
else:
print("It is not a Harshad Number")

Input/Output:
Enter a number:156