0cy4fw
Last Updated: April 09, 2017
·
20
· wilsontovar
Profile 2

Generar una serie del tipo: -1 + 1/2 -4 + 1/8 - 16 + 1/32 -...

Generar una serie del tipo: -1 + 1/2 -4 + 1/8 - 16 + 1/32 -...
[C++] - CodeBlocks :3

#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;
}
Say Thanks
Respond
Awesome Job

E20ce6a2 ca1f 11e7 82be 7f617c8310c9
SENIOR DEVELOPER (m/w)
·
Berlin, Köln, Hamburg, München
·
Full Time