I have to do the following:
Read a number and calculate the following sequence:
1-1/2+1/3-1/4+1/5...1/n
This is the way I'm doing it, but it doesn't work:
Code:#include <stdio.h> int main() { int a=0, n, suma=0; float den; printf ("\n Ingrese el número : "); scanf ("%i", &n); while (a<n) { if (a%2==0){ a++; den=1/a; suma-=den;} else{ a++; den=1/a; suma+=den;} } printf ("\n Resultado secuencia = %i", suma); return 0; }