Moved all programs in fort to a new folder, finished program2

This commit is contained in:
Mariano Uvalle 2019-05-04 23:01:29 -05:00
parent c7d211f0b5
commit 6a305f83c7
17 changed files with 2060 additions and 1844 deletions

View file

@ -0,0 +1,6 @@
program test
integer :: a
do a = 0, 2+1 then
print a, endline
end do
end program

View file

@ -0,0 +1,10 @@
goto 2
= 0 $50
+ 2 1 $0
<= $50 $0 $1
gotoF $1 11
print $50
print endline
+ $50 1 $2
= $2 $50
goto 4

View file

@ -0,0 +1,105 @@
program p1
integer [5][5] :: m1, m2, m3
integer :: i, j, k, cTemp, rTemp, temp, option
integer [3] :: columns, rows
subroutine readDim
do then
print 'Enter number of rows: '
read rTemp
if (rTemp <= 5 .and. rTemp > 0) then
exit
end if
print 'number of rows must be greater than 0 and less than 6', endline
end do
do then
print 'Enter number of columns: '
read cTemp
if (cTemp <= 5 .and. cTemp > 0) then
exit
end if
print 'number of columns must be greater than 0 and less than 6', endline
end do
end subroutine
subroutine readM1
do i = 0, rows(0) - 1 then
do j = 0, columns(0) - 1 then
print 'Enter value (', i, ',', j, ') for matrix 1', endline
read m1(i,j)
end do
end do
end subroutine
subroutine readM2
do i = 0, rows(1) - 1 then
do j = 0, columns(1) - 1 then
print 'Enter value (', i, ',', j, ') for matrix 2', endline
read m2(i,j)
end do
end do
end subroutine
subroutine sumMats
do i = 0, rows(0) - 1 then
do j = 0, columns(0) - 1 then
m3(i,j) = m1(i,j) + m2(i,j)
end do
end do
end subroutine
subroutine multMats
do i = 0, rows(2) - 1 then
do j = 0, columns(2) - 1 then
temp = 0
do k = 0, columns(0) - 1 then
temp = temp + m1(i,k) * m2(k,j)
end do
m3(i,j) = temp
end do
end do
end subroutine
subroutine printResult
do i = 0, rows(2) - 1 then
do j = 0, columns(2) - 1 then
print m3(i,j), ' '
end do
print endline
end do
end subroutine
do temp = 1, 2 then
print 'Enter dimensions for matrix ', temp, endline
readDim()
rows(temp - 1) = rTemp
columns(temp - 1) = cTemp
end do
readM1()
readM2()
do then
print 'Choose and option', endline
print '1 - Multiply the matrices', endline
print '2 - Sum the matrices', endline
read option
if (option == 1) then
if (columns(0) == rows(1)) then
rows(2) = rows(0)
columns(2) = columns(1)
multMats()
printResult()
else
print 'Sorry cannnot multiply matrices with theses dimensions', endline
end if
elif (option == 2) then
if (rows(0) == rows(1) .and. columns(0) == columns(1)) then
rows(2) = rows(0)
columns(2) = columns(0)
sumMats()
printResult()
else
print 'Sorry cannnot sum matrices with theses dimensions', endline
end if
else
print 'Not a valid option', endline
end if
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)', endline
read option
if (option == 0) then
exit
end if
end do
end program

View file

@ -0,0 +1,215 @@
goto 156
print 'Enter number of rows: '
read $279
<= $279 5 $0
> $279 0 $1
.and. $0 $1 $2
gotoF $2 9
goto 12
print 'number of rows must be greater than 0 and less than 6'
print endline
goto 2
print 'Enter number of columns: '
read $278
<= $278 5 $2
> $278 0 $0
.and. $2 $0 $1
gotoF $1 19
goto 22
print 'number of columns must be greater than 0 and less than 6'
print endline
goto 12
goback
= 0 $275
- $285 1 $2
<= $275 $2 $0
gotoF $0 47
= 0 $276
- $282 1 $4
<= $276 $4 $5
gotoF $5 44
print 'Enter value ('
print $275
print ','
print $276
print ') for matrix 1'
print endline
* $275 5 $6
+ $276 $6 $6
+ 200 $6 $6
read *6
+ $276 1 $7
= $7 $276
goto 29
+ $275 1 $7
= $7 $275
goto 25
goback
= 0 $275
- $286 1 $8
<= $275 $8 $9
gotoF $9 72
= 0 $276
- $283 1 $11
<= $276 $11 $12
gotoF $12 69
print 'Enter value ('
print $275
print ','
print $276
print ') for matrix 2'
print endline
* $275 5 $13
+ $276 $13 $13
+ 225 $13 $13
read *13
+ $276 1 $14
= $14 $276
goto 54
+ $275 1 $14
= $14 $275
goto 50
goback
= 0 $275
- $285 1 $15
<= $275 $15 $16
gotoF $16 98
= 0 $276
- $282 1 $18
<= $276 $18 $19
gotoF $19 95
* $275 5 $20
+ $276 $20 $20
+ 250 $20 $20
* $275 5 $21
+ $276 $21 $21
+ 200 $21 $21
* $275 5 $22
+ $276 $22 $22
+ 225 $22 $22
+ *21 *22 $23
= $23 *20
+ $276 1 $20
= $20 $276
goto 79
+ $275 1 $20
= $20 $275
goto 75
goback
= 0 $275
- $287 1 $23
<= $275 $23 $21
gotoF $21 134
= 0 $276
- $284 1 $24
<= $276 $24 $25
gotoF $25 131
= 0 $280
= 0 $277
- $282 1 $27
<= $277 $27 $28
gotoF $28 124
* $275 5 $29
+ $277 $29 $29
+ 200 $29 $29
* $277 5 $30
+ $276 $30 $30
+ 225 $30 $30
* *29 *30 $31
+ $280 $31 $29
= $29 $280
+ $277 1 $29
= $29 $277
goto 110
* $275 5 $29
+ $276 $29 $29
+ 250 $29 $29
= $280 *29
+ $276 1 $29
= $29 $276
goto 105
+ $275 1 $29
= $29 $275
goto 101
goback
= 0 $275
- $287 1 $31
<= $275 $31 $30
gotoF $30 155
= 0 $276
- $284 1 $33
<= $276 $33 $34
gotoF $34 151
* $275 5 $35
+ $276 $35 $35
+ 250 $35 $35
print *35
print ' '
+ $276 1 $35
= $35 $276
goto 141
print endline
+ $275 1 $35
= $35 $275
goto 137
goback
= 1 $280
<= $280 2 $35
gotoF $35 172
print 'Enter dimensions for matrix '
print $280
print endline
call 2
- $280 1 $36
+ 285 $36 $37
= $279 *37
- $280 1 $37
+ 282 $37 $38
= $278 *38
+ $280 1 $38
= $38 $280
goto 157
call 23
call 48
print 'Choose and option'
print endline
print '1 - Multiply the matrices'
print endline
print '2 - Sum the matrices'
print endline
read $281
== $281 1 $38
gotoF $38 193
== $282 $286 $40
gotoF $40 190
= $285 $287
= $283 $284
call 99
call 135
goto 192
print 'Sorry cannnot multiply matrices with theses dimensions'
print endline
goto 209
== $281 2 $44
gotoF $44 207
== $285 $286 $46
== $282 $283 $49
.and. $46 $49 $50
gotoF $50 204
= $285 $287
= $282 $284
call 73
call 135
goto 206
print 'Sorry cannnot sum matrices with theses dimensions'
print endline
goto 209
print 'Not a valid option'
print endline
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)'
print endline
read $281
== $281 0 $53
gotoF $53 215
goto 216
goto 174

View file

@ -0,0 +1,42 @@
program p2
integer [10] :: vec
integer :: i, j, size, temp
subroutine readVec
do i = 0, size - 1 then
print 'Enter element ', i, ' of the vector', endline
read vec(i)
end do
end subroutine
subroutine printVec
do i = 0, size - 1 then
print vec(i), ' '
end do
print endline
end subroutine
subroutine readDim
do then
print 'Enter the size of the vector to sort', endline
read size
if (size <= 10 .and. size > 0) then
exit
end if
print 'The size of the vector must be greater than 0 and less than or equal to 10', endline
end do
end subroutine
subroutine sort
do i = 0, size - 2 then
do j = 0, size - i - 2 then
if (vec(j) > vec(j + 1)) then
temp = vec(j)
vec(j) = vec(j+1)
vec(j+1) = temp
end if
end do
end do
end subroutine
readDim()
readVec()
sort()
print 'Sorted vector: '
printVec()
end program

View file

@ -0,0 +1,74 @@
goto 70
= 0 $210
- $212 1 $0
<= $210 $0 $1
gotoF $1 15
print 'Enter element '
print $210
print ' of the vector'
print endline
+ 200 $210 $2
read *2
+ $210 1 $3
= $3 $210
goto 4
goback
= 0 $210
- $212 1 $3
<= $210 $3 $4
gotoF $4 26
+ 200 $210 $5
print *5
print ' '
+ $210 1 $5
= $5 $210
goto 18
print endline
goback
print 'Enter the size of the vector to sort'
print endline
read $212
<= $212 10 $5
> $212 0 $6
.and. $5 $6 $7
gotoF $7 36
goto 39
print 'The size of the vector must be greater than 0 and less than or equal to 10'
print endline
goto 28
goback
= 0 $210
- $212 2 $7
<= $210 $7 $5
gotoF $5 69
= 0 $211
- $212 $210 $6
- $6 2 $8
<= $211 $8 $6
gotoF $6 66
+ 200 $211 $9
+ $211 1 $10
+ 200 $10 $11
> *9 *11 $12
gotoF $12 63
+ 200 $211 $12
= *12 $213
+ 200 $211 $12
+ $211 1 $9
+ 200 $9 $11
= *11 *12
+ $211 1 $12
+ 200 $12 $11
= $213 *11
+ $211 1 $11
= $11 $211
goto 47
+ $210 1 $11
= $11 $210
goto 42
goback
call 28
call 2
call 40
print 'Sorted vector: '
call 16

View file

@ -0,0 +1,53 @@
program test
integer :: option, result, x, y, counter, counter2,factorial, exponential
do then
print 'Choose and option', endline
print '1 - Calculate the factorial of a number', endline
print '2 - Calculate a number to the power of another number', endline
print '3 - Calculate e to the power of a number', endline
read option
if (option == 1) then
print 'Enter the number', endline
read x
result = 1
do counter = 1, x then
result = result * counter
end do
print 'The result is : ', result, endline
elif (option == 2) then
print 'Enter the base', endline
read x
print 'Enter the exponent', endline
read y
result = 1
do counter = 1, y then
result = result * x
end do
print 'The result is : ', result, endline
elif (option == 3) then
print 'Enter the exponent', endline
read x
result = 0
do counter = 0, 10 then
factorial = 1
do counter2 = 1, counter then
factorial = factorial * counter2
end do
exponential = 1
do counter2 = 1, counter then
exponential = exponential * x
end do
result = result + exponential / factorial
end do
print 'The result is : ', result, endline
else
print 'Not a valid option', endline
end if
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)', endline
read option
if (option == 0) then
exit
end if
end do
end program

View file

@ -0,0 +1,95 @@
goto 2
print 'Choose and option'
print endline
print '1 - Calculate the factorial of a number'
print endline
print '2 - Calculate a number to the power of another number'
print endline
print '3 - Calculate e to the power of a number'
print endline
read $200
== $200 1 $0
gotoF $0 29
print 'Enter the number'
print endline
read $202
= 1 $201
= 1 $204
<= $204 $202 $0
gotoF $0 25
* $201 $204 $1
= $1 $201
+ $204 1 $1
= $1 $204
goto 18
print 'The result is : '
print $201
print endline
goto 89
== $200 2 $1
gotoF $1 50
print 'Enter the base'
print endline
read $202
print 'Enter the exponent'
print endline
read $203
= 1 $201
= 1 $204
<= $204 $203 $1
gotoF $1 46
* $201 $202 $2
= $2 $201
+ $204 1 $2
= $2 $204
goto 39
print 'The result is : '
print $201
print endline
goto 89
== $200 3 $2
gotoF $2 87
print 'Enter the exponent'
print endline
read $202
= 0 $201
= 0 $204
<= $204 10 $2
gotoF $2 83
= 1 $206
= 1 $205
<= $205 $204 $3
gotoF $3 68
* $206 $205 $4
= $4 $206
+ $205 1 $4
= $4 $205
goto 61
= 1 $207
= 1 $205
<= $205 $204 $4
gotoF $4 77
* $207 $202 $5
= $5 $207
+ $205 1 $5
= $5 $205
goto 70
/ $207 $206 $5
+ $201 $5 $6
= $6 $201
+ $204 1 $6
= $6 $204
goto 57
print 'The result is : '
print $201
print endline
goto 89
print 'Not a valid option'
print endline
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)'
print endline
read $200
== $200 0 $6
gotoF $6 95
goto 96
goto 2

View file

@ -0,0 +1,3 @@
program test
print 'hello', ' ', 'world', endline
end program

View file

@ -0,0 +1,4 @@
print 'hello'
print ' '
print 'world'
print endline

View file

@ -0,0 +1,59 @@
program matrix
integer [100][100] :: matrix1, matrix2, resultMatrix
integer :: m1Rows, m1Columns, m2Rows, m2Columns, temp, temp2
subroutine sumMatrices
do temp = 1, m1Rows then
do temp2 = 1, m1Columns then
resultMatrix(temp,temp2) = matrix1(temp,temp2) + matrix2(temp,temp2)
resultMatrix(1,1) = 2
end do
end do
end subroutine
subroutine printResultMatrix
do temp = 1, m1Rows then
do temp2 = 1, m1Columns then
print resultMatrix(temp,temp2) , ' '
end do
print '\n'
end do
end subroutine
subroutine readMatrix1
do temp = 1, m1Rows then
do temp2 = 1, m1Columns then
print 'Enter value (', temp, ',', temp2, ') For matrix1\n'
read matrix1(temp,temp2)
end do
end do
end subroutine
subroutine readMatrix2
do temp = 1, m1Rows then
do temp2 = 1, m1Columns then
print 'Enter value (', temp, ',', temp2, ') For matrix2\n'
read matrix2(temp,temp2)
end do
end do
end subroutine
subroutine readM1Dimensions
print 'Enter the rows of the first matrix'
read m1Rows
print 'Enter the columns for the first matrix'
read m1Columns
end subroutine
subroutine readM2Dimensions
print 'Enter the rows of the second matrix'
read m2Rows
print 'Enter the columns for the second matrix'
read m2Columns
end subroutine
do then
readM1Dimensions()
readM2Dimensions()
if (m1Rows == m2Rows) then
exit
end if
end do
readMatrix1()
readMatrix2()
sumMatrices()
printResultMatrix()
end program

View file

@ -0,0 +1,107 @@
= 1 $30057
<= $30057 $30053 $0
gotoF $0 25
= 1 $30058
<= $30058 $30054 $1
gotoF $1 22
* 0 100 $30052
+ $30058 $30052 $30052
+ 20052 $30052 $30052
* 0 100 $10050
+ $30058 $10050 $10050
+ 50 $10050 $10050
* 0 100 $20051
+ $30058 $20051 $20051
+ 10051 $20051 $20051
+ *10050 *20051 $2
= $2 *30052
= 2 $20153
+ $30058 1 $2
= $2 $30058
goto 5
+ $30057 1 $2
= $2 $30057
goto 2
= 1 $30057
<= $30057 $30053 $2
gotoF $2 45
= 1 $30058
<= $30058 $30054 $3
gotoF $3 40
* 0 100 $30052
+ $30058 $30052 $30052
+ 20052 $30052 $30052
print *30052
print ' '
print endline
+ $30058 1 $4
= $4 $30058
goto 29
print '
'
print endline
+ $30057 1 $4
= $4 $30057
goto 26
= 1 $30057
<= $30057 $30053 $4
gotoF $4 67
= 1 $30058
<= $30058 $30054 $5
gotoF $5 64
print 'Enter value ('
print $30057
print ','
print $30058
print ') For matrix1
'
print endline
* 0 100 $10050
+ $30058 $10050 $10050
+ 50 $10050 $10050
read *10050
+ $30058 1 $6
= $6 $30058
goto 49
+ $30057 1 $6
= $6 $30057
goto 46
= 1 $30057
<= $30057 $30053 $6
gotoF $6 89
= 1 $30058
<= $30058 $30054 $7
gotoF $7 86
print 'Enter value ('
print $30057
print ','
print $30058
print ') For matrix2
'
print endline
* 0 100 $20051
+ $30058 $20051 $20051
+ 10051 $20051 $20051
read *20051
+ $30058 1 $8
= $8 $30058
goto 71
+ $30057 1 $8
= $8 $30057
goto 68
print 'Enter the rows of the first matrix'
print endline
read $30053
print 'Enter the columns for the first matrix'
print endline
read $30054
print 'Enter the rows of the second matrix'
print endline
read $30055
print 'Enter the columns for the second matrix'
print endline
read $30056
== $30053 $30055 $8
gotoF $8 104
goto 105
goto 101

View file

@ -0,0 +1,14 @@
program test
integer [10][10] :: a
integer :: i, j, counter
i = 1
j = 2
a(i) = 1
a(j) = 2
print 'a(i) = ', a(i), endline
print 'a(j) = ', a(j), endline
a(i) = a(j) + a(i)
print 'a(i) = ', a(i), endline
i = j + 2
print i, endline
end program

View file

@ -0,0 +1,44 @@
goto 2
= 1 $300
= 2 $301
* $300 10 $0
+ 0 $0 $0
+ 200 $0 $0
= 1 *0
* $301 10 $0
+ 0 $0 $0
+ 200 $0 $0
= 2 *0
print 'a(i) = '
* $300 10 $0
+ 0 $0 $0
+ 200 $0 $0
print *0
print endline
print 'a(j) = '
* $301 10 $0
+ 0 $0 $0
+ 200 $0 $0
print *0
print endline
* $300 10 $0
+ 0 $0 $0
+ 200 $0 $0
* $301 10 $1
+ 0 $1 $1
+ 200 $1 $1
* $300 10 $2
+ 0 $2 $2
+ 200 $2 $2
+ *1 *2 $3
= $3 *0
print 'a(i) = '
* $300 10 $0
+ 0 $0 $0
+ 200 $0 $0
print *0
print endline
+ $301 2 $0
= $0 $300
print $300
print endline