HARSHAD NUMBER OR NOT
Consider the following I/O samples.
SAMPLE INPUT: 6804
SAMPLE OUTPUT: HARSHAD NUMBER
A number is called HARSHAD NUMBER if it is divisible by the sum of its digits.
1729 =1+7+2+9 = 19
1729/19 = 91
C PROGRAM:#include<stdio.h>int main()
{
int n,temp,sum=0,ans;
scanf("%d",&n);
temp = n;
while(temp)
{
sum=sum+temp%10;
temp = temp/10;
}
ans=n%sum;
if(ans == 0)
printf("Harshad number");
else
printf("Not a Harshad number");
return 0;
}
OUTPUT:The given source code in C program "FOR HARSHAD NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment