+KayBee Posted January 11, 2019 Share Posted January 11, 2019 Hi Atarians, I am self teaching BASIC and don't know where to go from here. If I have an array of 100 random integers, and I want to subtract each subscripted value from the one preceding it. 10 DIM X(100) 20 FOR A=1 TO 100 30 X(A)=INT(10*RND(1))+1 ? 50 PRINT? 60 NEXT A goal: X(100)-X(99) print result X(99)-x(98) print result etc. Any guidance would be appreciated. Thank you for your time. KB Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 11, 2019 Share Posted January 11, 2019 100 FOR A=100 TO 2 STEP -1 110 ? X(A)-X(A-1) 120 NEXT A You could just do the calculation inside the main loop but the first value wouldn't be calculatable since you need 2 elements defined before you can subtract. Note arrays have element (0) so you could just DIM to 99 and use it. Quote Link to comment Share on other sites More sharing options...
E474 Posted January 11, 2019 Share Posted January 11, 2019 90 X(100)=INT(10*RND(1))+1 100 FOR A=99 TO 1 STEP -1 110 X(A)=INT(10*RND(1))+1 120 ? X(A+1)-X(A) 130 NEXT A Or similar (no access to Basic at the moment) Quote Link to comment Share on other sites More sharing options...
+KayBee Posted January 13, 2019 Author Share Posted January 13, 2019 Yup, got it now. Thank you gentlemen. And of course it seems obvious once you know the answer. Ahhh learning... Cheers, KB 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.