0
C program to print the sum of the series -x+x^2-x^3+.......n terms
6 Answers
+ 1
There is no need to call the function of power computation. It is quite possible to do by sequential calculation of this added element of the sequence from the previous element. This also works faster.
https://code.sololearn.com/cP4fh9h149ve/?ref=app
0
#include <iostream>
#include <cmath>
int main() {
int n;
// enter value of n
std::cin >> n;
double x;
// enter value of x
std::cin >> x;
int sum = 0;
for (int i = 1; i <= n; i++)
sum += pow(-1, i)*pow(x, i);
// print final sum
std::cout << sum;
return 0;
}
0
i need a c program not a c++... can u help me with it?
0
yes, changed into C
https://code.sololearn.com/cD2qvp0j44kS/?ref=app
0
thanks a lot😊
0
i cant get output