Write a program to check the number is strong number or not.
SOLUTION:
/*
* Program to check the number is strong number or not.
* Written by Shaeed Khan.
* Date: 04 Aug 2014
* Version- 1.0
* Language: C
*/
#include < stdio.h >
#include < stdlib.h >
void main()
{
int x,n;
printf("Enter a number :");
scanf("%d",&n);
x=strong(n);
if(x==n)
printf("Strong");
else
printf("Not strong");
}
int strong(int n)
{
int s=0,r,f;
while(n>0)
{
r=n%10;
f=fact(r);
s=s+f;
n=n/10;
}
return s;
}
int fact(int n)
{
int f=1;
while(n>0)
{
f=f*n;
n--;
}
return f;
}
No comments:
Post a Comment