I'm trying create a function, but when it returns my value instead of a number I get a combination of letters and numbers.
I input: 0 and 4
I should get something like: 3.313
I get: 1.#QNAN0
Here's my code, do I need to do something different with my return command?
thank you
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
float secant ( float x_lower,float x_upper);
main()
{
float root, lower_bound, upper_bound ;
printf("\n\nInput lower bound: ");
scanf("%d", &lower_bound);
printf("\n\nInput upper bound: ");
scanf("%d", &upper_bound);
root = secant ( lower_bound, upper_bound );
printf("\n\n answer is: %f ",root);
getchar();
getchar();
}
float secant ( float x_lower,float x_upper) {
int i ;
float xo, xi ;
for ( i = 1 ; i < 4 ; i++ ) {
xo = exp ( -pow (x_lower , 2) ) - cos ( x_lower ) - 1 ;
xi = exp ( -pow (x_upper , 2) ) - cos ( x_upper ) - 1 ;
x_upper = xi - ( xi/(xo-xi) ) * ( x_lower - x_upper ) ;
}
return x_upper ;
}