Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

110 23 Integer handling Two special arithmetical functions are provided which produce integer (ie whole number) results. These integer functions are DIV and MOD (DIVision and MODulus). The result of a normal division has two parts – the whole number part and the remainder. Normally the remainder is quoted as a decimal fraction. Thus 11/4 = 2.75 or 2ѕ However the functions DIV and MOD enable the whole number part and the remainder to be calculated separately. Thus 11 DIV 4 = 2 (ie 4 goes into 11 two times) and 11 MOD 4 = 3 (ie the remainder is 3). A simple division test shows how they can be used.

5 CLS 10 PRINT "Division test!" 20 PRINT "Answer with a whole number, and a" ' "remainder" 30 REPEAT 40 X=RND(100) 50 Y=RND(10) 60 PRINT ' "What is ";X;" divided by ";Y 70 INPUT A 80 INPUT "Remainder? "B 90 IF A=Y DIV Y AND B=X MOD Y THEN PRINT "That's correct" ELSE PRINT "That's wrong" 100 PRINT ' "Press any key to continue" 110 T=GET 120 UNTIL FALSE DIV and MOD are used whenever you are trying to convert units – for example seconds into minutes. Thus 500 seconds is 500 DIV 60 minutes and 500 MOD 60 seconds – that is 8 minutes 20 seconds. For example this program prints a 24 hour clock