by Dinesh Thakur Category: Control Structures

                                Sum-of-Series

#include <iostream.h>
 
#include <math.h>
 
#include<conio.h>
 
void main()
 
{
 
     float Term, Term1,Diff,Sum,X;
 
     int N,I;
 
     clrscr();
 
     do
 
         {
 
                     N=1;
 
                     cout<<"Enter the value of X\n";
 
                     cin>>X;
 
                 cout<<"Value of X ="<<X<<" ";
 
                     Term=X;
 
                     Sum=1 + Term;
 
                     I=2;
 
                do
 
                 {
 
                     Term1 =X*(Term/I);
 
                      I=I+1;
 
                      Sum=Sum+Term1;
 
                      Diff=fabs(Term1- Term);
 
                      cout<<"Sum ="<<Sum<<" Diff=" <<Diff<<"\n";
 
                      Term=Term1;
 
                 }
 
                 while (Diff>(0.1e-11));
 
                      cout<<"Sum of the Series "<<Sum<<"\n";
 
                      N=N+1;
 
        }
 
                  while (N>2);
 
                  getch();
 
}
 

sum of the series using do..while loop



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles