0

here is my code for ln(x) but for all 1<=x<2 its output is zero , can anyone please find the mistake in it

#include<iostream> #include<math.h> using namespace std; double ln(double x) { double a=1,b,c,i=1,d=0,l=1; x=x-1; if(x<=1) { c=-x; while(a/i>0.00000001 || a/i<-0.00000001) { a=a*c; i++; d=d+a/i; } return x*(1+d); } if(x>1) { while(x>pow(2,l)) l++; return (l-1)*ln(2)+ln(x/pow(2,l-1)); } } int main() { int k; cin>>k; cout<<ln(k); }

24th Feb 2017, 2:02 PM
chandan reddy
chandan reddy - avatar
2 Answers
0
i think you must first assign value before using it .
24th Feb 2017, 2:36 PM
dagi
dagi - avatar
0
what value i must assign ??
26th Feb 2017, 6:36 PM
chandan reddy
chandan reddy - avatar