Niven Number is a number which is divisible by sum of it’s digits.
Example 1: 18. 1+8 = 9. We observe that 18 is divisible by sum of it’s digits 9. Hence it is a Niven Number.
Example 2: 15. 1+5 = 6. Here 15 is not divisible by it’s sum of digits 6. Hence it is not a Niven Number.
C
#include <stdio.h>
void main()
{
int n=0,r=0,s=0,nCopy=0;
printf("Enter a number: ");
scanf("%d",&n);
nCopy=n;
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
if((nCopy%s)==0)
{
printf("%d is a Niven Number",nCopy);
}
else
{
printf("%d is not a Niven Number",nCopy);
}
}C