Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

#include <iostream>

#include <conio.h>
using namespace std;
using namespace System;
int validar() {
int n;
do
{
cout << "Ingrese el N: ";
cin >> n;
} while (n <= 0);
return n;
}
void calcularSerie(int n) {
int b = 0;
float suma = 0;
do {
if (b % 2 == 0) {
suma = suma + 1 / pow(2, b);
cout << "+ 1/" << (pow(2, b)) << " \t";
}
else {
suma = suma - 1 / pow(2, b);
cout << "- 1/" << (pow(2, b)) << " \t";
}

b++;
} while (b < n);

cout << "\nLa suma es: " << suma << endl;

}
int main() {
int n;
n = validar();
calcularSerie(n);

system("pause>0");
return 0;
}

You might also like