// This program is based on the .NET platform, the compilation environment is Microsoft Visual C .NET // for the modification of the VC 6.0 platform, just replace stdafx.h to Iostream.h, then remove "Using Namespace STD in the main function" "/ / About the design code of the counter, you need to make big surgery to optimize the code, make it simple #include
Double Gexian (double xk0, double xk) // iterative function, cutting method {ge ; double xk1; cout << "xk0 =" << xk0 << '/ n' << "xk =" << xk << '/ n'; // iterative formula XK1 = xk-f (xk) * (xk-xk0) / (f (xk) -f (xk0)); // iterative replacement xk0 = xk; xk = xk1; // Cout << "XK1 =" << xk1 << '/ n' << endl; // Judgment Whether to continue iterative operation while (FABS (XK1))> EPS) XK1 = Gexian (xk0, xk); // Cout << "The number of iterations is:" << ge << endl; returnix xk1;}
Double newton (double x) // iterative function, Newton method {Double Tem; TEM = X- (x * x 2 * x-3) / (2 * x 2); return tem;}
Double main_gexian () // Primitive {cout << "Cutting Line / N"; COUT << "Enter a letter (e exit):"; char exit; // Define the export cin >> EXIT; COUT << " Description: Enter two unequal numbers ./n "; double x_k0, x_k, tmp_1; while (exit! = 'E') {cout <<" input two numbers: "; // Input CIN >> X_K0 >> X_K; // Root TMP_1 = Gexian (x_k0, x_k); cout << "root" << TMP_1 << '/ n'; // Export Cout << "iterative number is:" << GE << Endl; cout << "Enter letters (e exit):"; cin >> exit;} return 0;
Double main_newton () // Main function {cout << "Newton Fa / N"; cout << "Description: Enter a non -1 number. Enter -1 exit ..." << '/ n'; cout << "Enter:"; Double S; CIN >> S; cout << Endl; while (s! = - 1) {int count1 = 0, count2 = 0; // count value while (s! = - 1) /// Positive range operation {double tmp_x = newton (s); double f_x = f (tmp_x); count1 ; if (FABS (f_x) While (S0! = - 1) // Negative section operation {double tmp_y = newton (s0); double f_y = f (tmp_y); count2 ; if (F_Y) IF (s == - 1) cout << "end!"; // Judgment division feasibility return 0;} Double main () {char select; while (1) {cout << "Select iterative mode / N (A is a cutting method, B is Newton Law, C exits):"; cin >> SELECT; cout << '/ N '; if (select ==' a ') {main_gexian ();} else if (select ==' b ') {main_newton ();} else} (select ==' c ') Break;} return 0; }