THE GIVEN NUMBER IS STRONG NUMBER OR NOT - C-Tutorial

Latest

Friday, 20 January 2017

THE GIVEN NUMBER IS STRONG NUMBER OR NOT

/* PROGRAM FOR THE GIVEN NUMBER IS STRONG NUMBER OR NOT */


#include<stdio.h>
#include<conio.h>

void main()
{
int sum=0,i,n,a,fact,temp;
clrscr();
printf("\n Enter a number: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
a=n%10;
fact=1;
for(i=1;i<=a;i++)
{
fact=fact*i;
}
sum=sum+fact;
n=n/10;
}
if(sum==temp)
printf("\n The given number is strong number %d",temp);
else
printf("\n The given number is not a strong number %d",temp);
getch();
}

Example:    A number is called strong number if sum of the factorial of its digit is equal to number itself. For example: 145 since
1! + 4! + 5! = 1 + 24 + 120 = 145

No comments:

Post a Comment