C Program:
#include<stdio.h>
long int factorial(int n)
{
if (n == 0)
return 1;
else
return (n * factorial(n - 1));
}void main()
{
int n, t;
int sum = 0;
printf("\nEnterthe number");
scanf("%i", &n);
t = n;
while (t != 0)
{
sum += factorial(t % 10);
t /= 10;
}
if (sum == n)
printf("\nIt is a Strong number");
else
printf("\nIt is not a Strong number");
}
C++ Program:
#include<iostream.h>
long int factorial(int n)
{
if (n == 0)
return 1;
else
return (n * factorial(n - 1));
}int main()
{
int n, t;
int sum = 0;
cout<<"\nEnterthe number";
cin>>n;
t = n;
while (t != 0)
{
sum += factorial(t % 10);
t /= 10;
}
if (sum == n)
cout<<"\nIt is a Strong number";
else
cout<<"\nIt is not a Strong number";
return 0;
}
No comments :
Post a Comment