NIVEN/HARSHAD NUMBER:
Any number which is divisible by sum of its own digits.
digit = 21
sum=2+1 = 3
division =21%3=7.
conditions true for niven/harshad number.
Program.
#include<stdio.h>
#include<math.h>
int main()
{
int j,p,n,temp,sum=0;
printf("enter number: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
j=n%10;
sum=sum+j;
n=n/10;
}
n=temp;
p=temp/sum;
printf("%d/%d=%d",n,sum,p);
if(temp%sum==0)
printf("\n(niven/harshad) number ");
else
printf("\nnot a (niven/harshad) number");
return 0;
}
Comments
Post a Comment