hey guys what's wrong with this codes? =/ #include <stdio.h> #include <math.h> double f(double x); double dfdx(double x); int main(){ int i=0; double x_eski = 10.0, // tahmini kok, x0 x_yeni = 10.0, eps = 1.0e-3, // yakinsama kriteri hata = 100.0; // buyuk bir sayi printf("%d %e\n", i, x_yeni); while(hata > eps && i < 30){ x_yeni=x_eski - f(x_eski)/dfdx(x_eski); i++; printf("%d %e\n", i, x_yeni); hata = fabs(x_yeni - x_eski) / fabs(x_eski); x_eski = x_yeni; } if(i == 30) printf("Raphson Newton yinelemesi yakinsamadý!\n"); return 0; } double f(double x){ return(x*x*x + x*x + x - 1.0); } double dfdx(double x){ return(3.0*x*x + 2.0*x + 1.0); } Code (markup):
If this is C++ code, I suggest you avoid C style output(printf), use C++ style output(cout<<), do not forget include<iostream>, and use english for comments please...XD, We can not even read it...
That is C style, not C++ If it's just one main file, why bother defining prototypes, just do implementations at top, save a few lines.
The above code is not c++.It is just c code.There is no class in it. There is no printf function in c++ instead it has cout function.If it is c++ their should be included include<iostream> library function at header. so it not a c++ code. i suggset you to rename it has c code.