Tuesday, November 29, 2016

C++ Program For Strong Number and Factorial of Number

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:-

#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();
}



Output:-





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

Acer Nitro 5 Ryzen 7 4800H - Blender Open Data Benchmark | Blender BMW Benchmark

Hello friends in this video I have perform benchmark of Acer Nitro 5 Ryzen 7 4800H laptop using Blender Open data Benchmark tool. In this to...