109k views
2 votes
Display all the natural numbers from 1 to 100 that are exactly divisible by 3 and 7 using FOR … NEXT. Without using Mod

1 Answer

2 votes

Answer:

FOR i% = 1 TO 100

IF ((i%\3) = i%/3) AND ((i%\7) = i%/7) THEN

PRINT i%

END IF

NEXT i%

Step-by-step explanation:

Of course using MOD would be cleaner, but another way to check if a number is integer divisable is to compare the outcome of an integer division to the outcome of a floating-point division. If they are equal, the division is an integer division.

The program outputs:

21

42

63

84

User Jackocnr
by
5.0k points