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


Please Help Members By Posting Answers For Below Questions

Why do some versions of toupper act strangely if given an upper-case letter?

636


In a header file whether functions are declared or defined?

631


What are the types of variables in c?

582


Explain what are the __date__ and __time__ preprocessor commands?

596


What should malloc(0) do?

619






int far *near * p; means

3125


Can include files be nested?

631


How can I manipulate individual bits?

611


FILE PROGRAMMING

1781


Does c have class?

615


What is the difference between local variable and global variable in c?

693


What is the difference between exit() and _exit() function?

610


What do you mean by scope of a variable in c?

546


What is void pointers in c?

593


How can I open a file so that other programs can update it at the same time?

665