привет!
Я бы хотел транслировать эту программу из Basic в С. Может ли ктонебуть помочь?
The Visual Basic code is below:
Код:
1 REM POLYNOMIAL EQUATION SOLUTION PROGRAM
2 REM THIS PROGRAM USES NEWTON'S METHOD TO FIND
3 REM A SOLUTION FOR A POLYNOMIAL EQUATION OF DEGREE 4
10 DIM A(4)
20 FOR I = 0 TO 4
30 PRINT "ENTER COEFFICIENT OF X^"; I; " : "; : INPUT A(I)
40 NEXT I
50 INPUT "INITIAL GUESS FOR SOLUTION: " ; X
60 GOSUB 200 'CALCULATE Y = F(X)
65 IF ABS(Y) < 0.0001 THEN GOTO 100
70 GOSUB 300 'CALCULATE DENOMINATOR
80 X = X - Y/D
90 GOTO 60
100 REM -- SOLUTION FOUND --
110 PRINT "SOLUTION: " ; X
120 END
200 REM CALCULATE Y = F9X0
210 Y = 0
220 FOR I = 0 TO 4
230 Y = Y + A(I)*X^I
240 NEXT I
250 RETURN
300 REM CALCULATE DENOMINATOR
310 D = 0
320 FOR I = 0 TO 3
330 D = D + A(I + 1)*(I = 1)*X^I
340 NEXT I
350 RETURN
360 REM WARNING -- SOMETIMES THIS PROGRAM WILL GO AROUND
370 REM IN AN ENDLESS LOOP
380 REM IN THAT CASE, INTERRUPT THE PROGRAM AND TRY AGAIN
390 REM WITH ANOTHER INITIAL GUESS
400 REM HOWEVER, IF THERE ARE NO REAL SOLUTIONS, THEN
410 REM THE PROGRAM WILL NEVER FIND A SOLUTION
If you're interested, here's the problem: Write a computer program that reads in the coefficients of a fourth degree polynomial
and then finds the solution to the equation
. Have the computer read in an initial guess for the solution
, and then calculate a closer guess
from this formula:
Keep repeating the process of using this formula to find guesses that become closer to the solution. When you find a value of
such that
, then treat that as the solution.