0

What is wrong with my code? I'm not getting my desired output. Answer for 1+x+x^2+x^3+.....

https://code.sololearn.com/cBfclBsSv8OC/?ref=app

22nd Aug 2022, 4:34 PM
Learning
2 Answers
+ 2
try this: #include <stdio.h> #include<math.h> int main() { int n,i,x,sum=0; printf ("enter x and n value"); scanf("%d %d",&x,&n); if (n>0) { for(i=0;i<=n;i++) { sum=sum+pow(x,i); } printf("sum is %d",sum); } return 0; }
22nd Aug 2022, 4:46 PM
Elmira
0
Learning Initialise x with 0 to avoid garbage value and start i with 0 till <= n
22nd Aug 2022, 4:50 PM
AÍąJ
AÍąJ - avatar