# C Program to check whether a number is Harshad number or not

## Write a C Program to find number is Harshad number or not.

In this program we will discuss of number is harshad number or not in C programming. In  mathematics, a Harshad number is a number that is  divisible by the sum of its digits. We use  while loop statement with following condition. Input consists of 1 integer.

Ex– Number is 21

it is divisible by own sum (1+2) of its digit(2,1)

Some other harshad number are 156,54,120 etc. ### Working:-

Step 1- Enter the number to be check.

Step 2- store the number in temporary variable.

Step 3- Initialise the while loop until the temp is not equal to zero

(i) Calculate the remainder of the temp,divided with the 10 and store in digit

(ii)  add the digit with sum and store it in the sum.

(ii) divide the temp with the 10 and store in the temp;

Step 4- find modulus of the number with sum and store in the res;

Step 5- if res equal to zero than given number is harshad number else the given number is not a harshad number.

Step 6- Stop. ### C Program:-

`#include<stdio.h>int main(){     //To initialize of variable     int number,temp,sum = 0, digit, res;    //To take user input    printf("enter any number : ");     scanf("%d",&number);    //store in temporary variable    temp = number;   //use while loop with this condition   while(temp!=0)   {       //to find last digit        digit=temp % 10;      //sum+=digit        sum = sum + digit;     //temp/=10        temp = temp / 10;   }   res = number % sum;   //check result is equal is to 0   if(res == 0)      //display       printf("%d is Harshad Number",number);   else      //display      printf("%d is not Harshad Number",number);  return 0;} `

### Output:-

`enter any number : 2121 is Harshad Numberenter any number : 1515 is not  Harshad Number` 