C++ program to check whether a number is a Harshad Number or not
Login/Signup to comment
One comment on “C++ program to check whether a number is a Harshad Number or not”
×
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
#include
using namespace std;
int main()
{
int num;
cout <>num;
int sum = 0;
int temp = num;
while (temp != 0)
{
int digit = num % 10;
sum = sum + digit;
temp = temp / 10;
}
if (num % sum == 0)
{
cout << num << " is harshad number";
}
else
{
cout << num << " is not harshad number";
}
}