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); }
2 Antworten
0
i think you must first assign value before using it .
0
what value i must assign ??