- 3

How to dispaly x+x^2+x^3+.....+x^n Without power (pow) function??

please solve this one please?? with c++

6th Sep 2017, 5:46 PM
Manu Chaudhary
Manu Chaudhary - avatar
2 ответов
+ 3
You can use only addition, multiplication and for loops. Using mathematics, we can write x+x^2+x^3+...+x^n as x(1+x(1+x(1+x(...(1+x(1+x))...)))). You can program it like below. double x, res=1; int n,i; cin>>n; cin>>x; for(i=0;i<n-1;i++){ res*=x; res+=1; } res*=x; cout<<res;
7th Sep 2017, 12:07 AM
OrbitHv [Inactive]
OrbitHv [Inactive] - avatar
14th Sep 2017, 11:46 AM
Manu Chaudhary
Manu Chaudhary - avatar