- 3
How to dispaly x+x^2+x^3+.....+x^n Without power (pow) function??
please solve this one please?? with c++
2 odpowiedzi
+ 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;