write a program to check whether a given integer is a strong
number or not?
[Hint:
145=1!+4!+5!
=1+24+120
=145]
Answer Posted / paul zarkovich
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
main()
{
int n,fact=1,sum=0,digit=0;
printf("Enter a number : ");
scanf("%d",&n);
int temp=n,a=n;
if(temp<10)
{
for(int i=temp;i>0;i--)
fact*=i;
if(n==fact)
printf("It is a strong no. ");
else
printf("It is not a strong no. ");
}
else
{
while(temp>10)
{
digit=temp%10;
temp/=10;
for(int i=digit;i>0;i--)
fact*=i;
sum+=fact;
fact=1;
}
for(int i=temp;i>0;i--)
fact*=i;
sum+=fact;
if(sum==n)
printf("It is a strong no. ");
else
printf("It is not a strong no. ");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What are the features of the c language?
What is the purpose of sprintf() function?
#include
Can you subtract pointers from each other? Why would you?
What is the difference between typedef and #define?
What is pointer to pointer in c with example?
Are c and c++ the same?
Is it better to use a macro or a function?
What is an array in c?
Is c pass by value or reference?
What library is sizeof in c?
What is typedf?
Why doesnt the call scanf work?
How main function is called in c?
What functions are used for dynamic memory allocation in c language?