0

C program to print the sum of the series -x+x^2-x^3+.......n terms

17th Dec 2017, 9:35 AM
Dhivi Cutiee
6 ответов
+ 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
20th Dec 2017, 12:28 PM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar
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; }
17th Dec 2017, 9:51 AM
Eligijus Silkartas
Eligijus Silkartas - avatar
0
i need a c program not a c++... can u help me with it?
18th Dec 2017, 4:36 AM
Dhivi Cutiee
18th Dec 2017, 7:11 AM
Eligijus Silkartas
Eligijus Silkartas - avatar
0
thanks a lot😊
19th Dec 2017, 3:24 AM
Dhivi Cutiee
0
i cant get output
20th Dec 2017, 2:23 AM
Dhivi Cutiee