Perform Niven or Harshad number in C programming?

All QuestionsCategory: C LanguagePerform Niven or Harshad number in C programming?
chetan shidling asked 4 years ago

I need short information.

1 Answers
chetan shidling answered 4 years ago

Here the code and output for Niven number:
 
#include <stdio.h>
int main()
{
int n, digit, sum=0, result=0, num;
printf(“Enter the number”);
scanf(“%d”, & n);
num = n;
while(num !=0)
{
digit = num % 10;
sum = sum + digit;
num = num/10;
}

result= n / sum;
printf(“Result is %d”, result);
return 0;
}
 
Output:
 
Enter the number 22
Result is 5