Generate a series: -1 + 1/2 -4 + 1/8 - 16 + 1/32 -...

/** Generar una serie del tipo: -1 + 1/2 -4 + 1/8 - 16 + 1/32 -... \ * * Wilson Tovar - 2016 \ * fb.me/space.wilson \ */ #include <iostream> #include <conio.h> #include <stdlib.h> using namespace std; int main() { int j, t, d, i; t = 2; j = 1; d = 2; cout << "Digite la cantidad de términos a generar: " << endl; cin >> i; system("cls"); cout << "-1" << endl; while ( j < i ) { if (t % 2 == 0 ) { cout << "1/" << d << endl; t = t + 1; } else { cout << d*(-1) << endl; t = t + 1; } d = d * 2; j = j + 1; } return 0; }
Generar una serie del tipo: -1 + 1/2 -4 + 1/8 - 16 + 1/32 -...

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.