'Program uses a random array and stores even and odd numbers in different files. (FreeBASIC)
Dim As Integer n, i, evennum, oddnum
input "Enter the no. of values in array=";n
Dim As Integer arr(n)
Randomize Timer
for i=1 to n
arr(i)=INT(RND(1) * 20) + 1 ' limits the numbers to 1 to 20
next i
print
for i=1 to n
print arr(i);" ";
next i
Open "even.txt" For Output As #1
for i=1 to n
if (arr(i) mod 2)=0 then
evennum=arr(i)
print #1, evennum;" ";
end if
next i
close #1
Open "odd.txt" For Output As #2
for i=1 to n
if (arr(i) mod 2) <> 0 then
oddnum=arr(i)
print #2, oddnum;" ";
end if
next i
close #2
print
print "Contents of file"; " even.txt"
Open "even.txt" For Input As #3
Dim As String s
Do until (EOF(3))
Line Input #3, s
print s
Loop
close #3
print
print "Contents of file"; " odd.txt"
Open "odd.txt" For Input As #4
Dim As String c
Do until (EOF(4))
Line Input #4, c
print c
Loop
close #4
Sleep
'Program uses a random array and stores even and odd numbers in different files. (FreeBASIC)
Dim As Integer n
input "Enter the no. of values in array=";n
Dim As Integer arr(n)
Randomize Timer
for i as integer=1 to n
arr(i)=INT(RND(1) * 20) + 1 ' limits the numbers to 1 to 20
print arr(i);" ";
next i
print
Open "even.txt" For Output As #1
Open "odd.txt" For Output As #2
for i as integer=1 to n
if (arr(i) mod 2)=0 then
print #1, arr(i);" ";
else
print #2, arr(i);" ";
end if
next i
close #2
close #1
print
print "Contents of file"; " even.txt"
Open "even.txt" For Input As #3
Dim As String s
Do until (EOF(3))
Line Input #3, s
print s
Loop
close #3
print
print "Contents of file"; " odd.txt"
Open "odd.txt" For Input As #4
Dim As String c
Do until (EOF(4))
Line Input #4, c
print c
Loop
close #4
Sleep
Open "even.txt" For Output As #1
Open "odd.txt" For Output As #2
for i as integer=1 to n
print #(arr(i) mod 2 + 1), arr(i);" ";
next i
close #2
close #1