Print and sum of following series 1! + 2! +3!.............upper limit

#include <iostream>
using namespace std;

void main ()
{

       cout<<"Please enter the upper limit here:";
       int upperlimit;
       cin>>upperlimit;

       int i=1;// initialization for outer loop
       int fact=1; //initialization for factorial variable
       int sum=0; // 'O' is the identity of addition

       while (i<=upperlimit)
       {
              cout<<i<<"! ";

                          ///////////////////
                          // for remove last '+' sign
                                  if (i!=upperlimit)
                                         cout<<"+";
                                  else
                                         ; // ; means a blank statement
                          //////////////////
             
                     for (int j=i;j>=1;j--)
                     {
                           fact=fact*j;
                          
                     }

              sum=sum+fact; // for sum the following series

              fact=1; // for remove old / garbage value of variable
             
              i++; // increamnet of the outer loop
      
       }
       cout<<"\n\nThe sum of the following series: "<<sum<<endl<<endl;

}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System