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;
}
Written by wilsontovar
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C++
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#