Subj : Re: Dartmouth BASIC to C To : comp.programming From : spinoza1111 Date : Sun Aug 07 2005 06:02 am Looks great, with a minor cavil. You simulate Dartmouth Basic's READ/DATA facility which would give a system error message if there was not enough DATA to READ in the pool of DATA. But if someone altered your simulated array of DATA and its initialization in the program text, your C would refer to an unknown location in memory. The program may well fail to give an error message, and would produce a wrong answer. I would have for this reason accessed DATA with a test of idx. Just a detail. And I may have missed something. It was probably a mistake for Kemeny and Kurtz to allow for reading data in source code but in itself the facility couldn't cause an error. There was in Dartmouth basic no chance for an error since everything was double precision (no strings). John Smith wrote: > Having nothing better to do on a Saturday morning, I was looking at > Kemeny & Kurtz's 1964 manual for BASIC: > > http://www.bitsavers.org/pdf/dartmouth/BASIC_Oct64.pdf > > Below is a C port of the first example program given in the manual. Can > it be improved while preserving, as much as possible, the structure of > the original BASIC program? > > /* > A C port of the 1st program given in Kemeny & Kurtz's > manual for 1964 Dartmouth BASIC. It solves a system of > linear equations with three different right sides. > > (A1*X1) + (A2*X2) = B1 > (A3*X1) + (A4*X2) = B2 > > The program in BASIC: > > 10 READ A1, A2, A3, A4 > 15 LET D = A1 * A4 - A3 * A2 > 20 IF D = 0 THEN 65 > 30 READ B1, B2 > 37 LET X1 = (B1 * A4 - B2 * A2) / D > 42 LET X2 = (A1 * B2 - A3 * B1) / D > 55 PRINT X1, X2 > 60 GOTO 30 > 65 PRINT "NO UNIQUE SOLUTION" > 70 DATA 1, 2, 4 > 80 DATA 2, -7, 5 > 85 DATA 1, 3, 4, -7 > 90 END > */ > > #include > #include > > int main(void) > { > int idx, sys; > double A1, A2, A3, A4; > double D, X1, X2, B1, B2; > > double DATA[] = {-7.0, 5.0, 1.0, 3.0, 4.0, -7.0}; > A1 = 1; > A2 = 2; > A3 = 4; > A4 = 2; > > D = A1 * A4 - A3 * A2; > if(D == 0.0) > { > printf("no unique solution\n"); > exit(EXIT_FAILURE); > } > idx = sys = 0; > for(sys = 0; sys < 3; sys++) > { > B1 = DATA[idx++]; > B2 = DATA[idx++]; > X1 = (B1 * A4 - B2 * A2) / D; > X2 = (A1 * B2 - A3 * B1) / D; > printf("%f %f\n", X1, X2); > } > > return 0; > } .