J
J
JW072020-12-06 19:56:53
C++ / C#
JW07, 2020-12-06 19:56:53

Why is the answer 0?

#include <stdio.h>
#include <math.h>
int main()
{
   int i,n,x;
   float s,z;
   printf("Введите x ");
   scanf("%d",&x);
   printf("Введите n ");
   scanf("%d",&n);
   s=0;
   for (i=1;i<=n;i++)
   {
   z=(1/i)*pow((x-1)/(x+1),i);
   s=s+z;
   i++;
   }
   printf("сумма равна %f",s);
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-12-06
@JW07

1/i- integer division, for x>1 it will give 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question