Posts

Showing posts with the label example

To print and sum of following series x + x^2 + x^3 + x^4..........x^n

#include <iostream> using namespace std; void main () {        cout<< "Please enter the Base (X) here:" ;        int base;        cin>>base;        cout<< "Please enter the power (n) here: " ;        int power;        cin>>power;        cout<< "\n" ; // for line space only        int i=1; //outer loop        int ans=1;        int sum=0;        while (i<=power)        {                     cout<<i<< "^" <<power<< " " ; ...

To 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<< "! " ;                          ///////////////////              ...

To print following series 1 2 3 0 5 6 7 0......upper limit

#include <iostream> using namespace std; void main () {        int upperlimit;        cout<< "Please enter the upperlimit " ;        cin>>upperlimit;        int i=1;        while (i<=upperlimit)        {                           if (i%4==0) // if any multiple of 4 is printed then it print 0                     cout<< "0" <<endl;              else                     cout...

To print following series 1 3 9 27 81....n

Source Code   #include <iostream> using namespace std; void main () {        int i=1;        int ans=1;        int upperlimit;        cout<< "Please enter the uper limit :" ;        cin>>upperlimit;        while (i<=2 && ans<=upperlimit) // infinite loop and a conditional loop        {              cout<<ans<< "\t" ;              ans=ans*3;               } }