Find Strong number and factorial of number using simple for loop in C++ Programing. In this program you can give any number to factorial or Strong number and it will give you answer.
Here suppose you give 1234 number it first check can given number is single number or separate number. ex 1234 - Single number then it give answer for given number.
or 1,2,3,4 - Separate numbers then it give answer for separate numbers.
Program:-
Here suppose you give 1234 number it first check can given number is single number or separate number. ex 1234 - Single number then it give answer for given number.
or 1,2,3,4 - Separate numbers then it give answer for separate numbers.
Program:-
#include<iostream.h>
|
#include<conio.h>
|
void main()
|
{
|
int
i,z,x,sum=0,n,f=1;
|
char
p;
|
clrscr();
|
cout<<"Enter
the no to factorial=";
|
cin>>n;
|
z=n;
|
cout<<n<<"\tIt
is single number or seperate(one/seperate)=";
|
cin>>p;
|
if(p=='o'||p=='O')
|
{
|
for(i=1;i<=n;i++)
|
{
|
f=f*i;
|
}
|
sum=f;
|
}
|
else
|
{
|
x=n%10;
|
for(;x!=0;x=n%10)
|
{
|
for(i=1;i<=x;i++)
|
{
|
f=f*i;
|
}
|
cout<<"\nfactorial
is "<<f;
|
sum=sum+f;
|
f=1;
|
n=n/10;
|
}
|
}
|
cout<<"\ntotal
factorial is "<<sum<<"\n";
|
if(sum==z)
|
{
|
cout<<z<<"="<<sum<<"\tIt
is Strong number";
|
}
|
else
|
{
|
cout<<z<<"!="<<sum<<"\tIt
is Not Strong number";
|
}
|
getch();
|
}
|
Please comment and give
Suggestion on this post, if you want any other program or help then type in
comment or contact me, and give feedback for this blogs.
No comments:
Post a Comment