FreeBASIC/SimpleExamples

List of simple examples for FreeBASIC programs:

1) Addition and subtraction of (random) integral numbers

' Program to create examples for addition and subtraction of integral numbers for output on printers
' source code for FreeBASIC; tested with PDFCreator

#lang "fblite"
dim as integer max,a,b,n,i

print
input "Maximum absolute value of the numbers [default: 100]: ";max
if max<2 then              
    max=100      
end if
print
input "How many examples [default: 25] ";n
if n<=0 then 
  n=25
end if
Lprint         ' output on the printer                
Lprint           
Lprint
Lprint "        ";n;" arithmetical exercises with integral numbers from ";-max;" to";max  
Lprint
Lprint

randomize      'initialize the rnd random-number generator
for i=1 to n 
    a=int(rnd*(2*max+1))-max
    b=int(rnd*(2*max+1))-max 
    Lprint using "       ###)   ";i;
    Lprint a;
    if b<=0 then                
       Lprint " -";abs(b)           
    else
       Lprint " +";b
    end if
    Lprint
    Lprint
next i  
Lprint Chr(12)   ' for output on computer screen use the command "sleep"