Perform Niven or Harshad number in C programming?


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: C LanguagePerform Niven or Harshad number in C programming?
chetan shidling asked 5 years ago

I need short information.

1 Answers
chetan shidling answered 5 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