For the following program, trace the output and write the results in exact FORMA
ID: 3853517 • Letter: F
Question
For the following program, trace the output and write the results in exact FORMAT in the given table. PROGRAM Learn_Format_part_I IMPLICIT NONE INTEGER, PARAMETER:: MAXIMUM = 5 INTEGER:: I REAL:: a = 203.67, b = - 84569.257 DO I = 1, MAXIMUM WRITE(*, "(lx, 2I6)") I, I * I END DO WRITE(*, "(lx, 2F12.7)") a, b END PROGRAM Learn_Format_part_I For the following FORMAT statement, write the exact output in the table given below. CHARACTER(LEN = 5):: a = "12345" CHARACTER:: b = "?" WRITE(*, "(lx, A1, A)") a, b WRITE(*, "(lx, A3, A)")a, b WRITE(*, "(lx, A5, A)")a, bExplanation / Answer
NOTE: I dont have the table format shown in assignment, so what i did is print the numbers(1 to 40) before printing code output. So it would be useful for you to fill the table by counting the digits where the output has come. Please let me know if you have any questions and i will revert back within 24 hours.
My recommendation is to copy the code and execute in your system. Because while copying the output format might differ.
Code:
program Learn_Format_part_I
IMPLICIT NONE
INTEGER, PARAMETER:: MAXIMUM = 5
INTEGER:: I
REAL:: a = 203.67, b = -84569.257
! printing digits as header so to understand where the output is formatted
DO I = 1, 40
write (*,"(I0)",advance='no') I
END DO
! printing newline
WRITE(*, '(A)')
! actual program output
DO I = 1, MAXIMUM
WRITE(*, "(1x, 2I6)") I, I*I
END DO
WRITE(*, "(1x, 2F12.7)") a, b
end program Learn_Format_part_I
Execution and output:
sh-4.3$ main
12345678910111213141516171819202122232425262728293031323334353637383940
1 1
2 4
3 9
4 16
5 25
203.6699982************
Code:
program Learn_Format_part_II
CHARACTER(LEN=5)::a = "12345"
CHARACTER::b = "?"
! printing the digits from 1 to 10 as header so we know where the output is formatted
DO I = 1, 10
write (*,"(I0)",advance='no') I
END DO
! printing new line
write(*,'(A)')
! actual program output
WRITE(*, "(1x, A1, A)") a,b
WRITE(*, "(1x, A3, A)") a,b
WRITE(*, "(1x, A5, A)") a,b
end program Learn_Format_part_II
Execution and output:
sh-4.3$ main
12345678910
1?
123?
12345?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.