| | |
mistake in simple math function
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
I made some simple mistake (conversion?) in my program.. I will be gratefull if anyone has an idea what's wrong with it
The problem is not with the algorithm itself so I am not explaining it - the problem is: why the condition placed in the code between // HERE and // HERE seems to be never true? (The function does not work correctly) Try this piece of code with 0.7 and 4 on entry.
The problem is not with the algorithm itself so I am not explaining it - the problem is: why the condition placed in the code between // HERE and // HERE seems to be never true? (The function does not work correctly) Try this piece of code with 0.7 and 4 on entry. C++ Syntax (Toggle Plain Text)
int s(int k) // factorial for integers { if (k==0 || k==1) {return 1;} else {return (s(k-1))*k;} } double newtonsymbol(double r, int k) { if (k<0) return 0; int s(int k); //that's factorial above static double t=r; double h; h=r+k-1.0; static double numerator=r; double denominator; std::cout<<h-t<<" "<<t<<std::endl; /* that's optional; it shows the mistake; the condition would be fulfilled if h-t==0 */ //HERE if (t==h) //HERE {denominator=s(k); std::cout<<"ok"<<std::endl; return (numerator/denominator);} if (h<-10) {return 3;} // that is added to stop the function so you can see what's going on {std::cout<<"not ok"<<std::endl; numerator=r*newtonsymbol(r-1,k));} } int main () { double p=0.7; int l=4; std::cout<<newtonsymbol(p,l); system("pause"); return 0; }
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: ShowWindow(FindWindow
- Next Thread: sum of 2 numbers in 16 radix
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






