Harshad
Number
It’s
also called Niven Number
A
Number which is divisible by sum of its digits is known as Harshad Numer or
Niven Number
For
example
1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30,……………
//Program
to check whether the entered number is Harshad or Not
#
include <stdio.h>
#
include <conio.h>
void
main()
{
//initialization of variables
int n,c,d,sum=0;
clrscr();
//Entry of integer value
printf("Enter any integer
value\n");
scanf("%d",&n);
//saving entered value in new variable c
c=n;
//loop initialization
while(c>0)
{
d = c % 10; //remainder
when divided by 10
sum = sum +d; //adding to
variable sum
c=c/10; //calculation of quotient
}
//check whether entered number is divisible
//by sum of the digits or not
if (n % sum == 0)
printf("%d is Harshad
Number",n);
else
printf("%d is not a
Harshad Number",n);
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.