What\'s wrong with this? I am trying to find arctanhx series. Below is the code
ID: 673433 • Letter: W
Question
What's wrong with this? I am trying to find arctanhx series. Below is the code
# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int i, n ;
float x, val, sum = 1, t = 1 ;
printf("Enter the value for x : ") ;
scanf("%f", &x) ;
printf(" Enter the value for n : ") ;
scanf("%d", &n) ;
val = x ;
x = x * 3.14159 / 180 ;
for(i = 1 ; i < n + 1 ; i++)
{
t = (double)(1 / (2 * i - 1) * pow(i, 2 * i + 1);
sum = sum + t ;
}
printf(" arctanh value of %f is : %8.4f", val, sum) ;
getch() ;
}
Explanation / Answer
Just remove the '(' before the 1 in the loop step t = (double)(1 / (2 * i - 1) * pow(i, 2 * i + 1); and write it as:
t = (double)1 / (2 * i - 1) * pow(i, 2 * i + 1);
Other than that, everything works good.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.