A NUMBER IS CALLED STRONG NUMBER IF SUM OF THE FACTORIAL OF ITS DIGIT IS EQUAL TO NUMBER ITSELF
FOR EXAMPLE: 145
I FACTORIAL IS 1
4 FACTORIAL IS 24
5 FACTORIAL IS 120
THEREFORE 1 + 24 +120 = 145
PROGRAM:
// prg to illustrate strong number
#include<stdio.h>
void main()
{
int n,i,r,sum=0,temp,fact;
printf("enter any number:");
scanf("%d",&n);
temp=n;
while(n != 0)
{
i=1,fact=1;
r=n %10;
while(i <= r)
{
fact = fact * i;
i++;
}
sum=sum +fact;
n = n /10;
}
if(sum==temp)
printf("%d is a strong number \n",temp);
else
printf("%d is not a strong number \n",temp);
}
output:
#include<stdio.h>
void main()
{
int n,i,r,sum=0,temp,fact;
printf("enter any number:");
scanf("%d",&n);
temp=n;
while(n != 0)
{
i=1,fact=1;
r=n %10;
while(i <= r)
{
fact = fact * i;
i++;
}
sum=sum +fact;
n = n /10;
}
if(sum==temp)
printf("%d is a strong number \n",temp);
else
printf("%d is not a strong number \n",temp);
}
output:
No comments:
Post a Comment