1 / 30

More Control over INPUT and OUTPUT I

2. More Control over INPUT and OUTPUT (I / O). The input and output facilities of any programming language are extremely important, because it is through these features of the language that communication between the user and the program is carried out.F, therefore, provides facilities for input an

clement
Download Presentation

More Control over INPUT and OUTPUT I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. 1 More Control over INPUT and OUTPUT (I / O)

    2. 2

    3. 3

    4. 4

    5. 5

    6. 6

    7. 7

    8. 8

    9. 9

    10. 10

    11. 11

    12. 12

    13. 13

    14. 14

    15. 15

    16. 16

    17. 17 Exercise 2 program test1 integer ::a,b real::c,d print*,"please enter an integer values which is more than 6 digit" read "(i4,t1,i4,t2,f4.1,t1,f4.2)",a,b,c,d print "(i4,a,i5,a,i5,a,f6.2,a,f6.2,a,f8.3)",a,& " minus",b," is",a-b,";",c," minus",d, " is",c-d end program test1

    18. 18 Exercise 3 program test2 character(len=6)::a,b,c Print*,”Please write your name” read "(a8,t1,a4,t1,a)",a,b,c print "(a10,tr12,a4,tr30,a)",a,b,c print "(a,t10,a,t52,a)",a,b,c end program test2

    19. 19 program five_digit_numbers integer::i integer,dimension(12)::arr arr = (/12345, 23456, 34567, 45678,& 90123, 12340, 24680, 46802,& 13579, 35791, 57913, 69649/) ! output for single column format example print*,"Single column of numbers" do i = 1 , 12 print "(t8,i2,1x,i5)",i,arr(i) end do ! output for four rows of three numbers print "(2/t3,a/)","Four rows of three numbers " print "(t8,i2,1x,3(i5,1x))", 1,arr(1:3) print "(t8,i2,1x,3(i5,1x))", 2,arr(4:6) print "(t8,i2,1x,3(i5,1x))", 3,arr(7:9) print "(t8,i2,1x,3(i5,1x))", 4,arr(10:12) ! a single line of numbers print "(2/t3,a/)", "A single line of numbers " print "(t2,12(i5,1x))", arr end program five_digit_numbers

    20. 20 program multi_record_example real :: a,b a = 12.25 b = 23.50 write(unit=6,fmt="(t10,a,3/,a,f6.2,a,f6.2,a,///,f7.2,2/,a,f10.3)")& "Multi-record example", & " The sum of ",a," and",b," is", a+b, & " Their product is",a*b end program multi_record_example

    21. 21 program railway_time_table integer,parameter::n=5 integer::i real,dimension(n)::arrival,departure integer,dimension(n)::platform character(len=10),dimension(n)::destination arrival=(/9.23, 9.28, 10.41, 10.48, 11.15/) departure=(/9.25, 9.32, 10.53, 10.53, 11.18/) platform=(/2, 1, 3, 2, 1/) destination=(/"Edinburgh"," London","Sheffield",& "Newcastle"," London"/) write(unit=6,fmt="(/a/2x,7('='),3x,9('='),3x,8('='),3x,11('='))") & " Arrival Departure Platform Destination" do i = 1 , n write(unit=6,fmt="(3x,f5.2,6x,f5.2,8x,i1,8x,a10)") & arrival(i),departure(i),platform(i),destination(i) end do end program railway_time_table

    22. 22 program test2 character(len=6)::a,b,c print *, "........................ STEPPER... Entering PROGRAM. Press Enter" print*,"program test2" read * print *, "........................ STEPPER... Before READ. Press Enter" print*,"read ""(a8,t1,a4,t1,a)"",a,b,c" read * read "(a8,t1,a4,t1,a)",a,b,c print *, "........................ STEPPER... After READ. Press Enter" read * print "(a8,tr2,a4,tr3,a)",a,b,c print*,"print ""(a8,tr2,a4,tr3,a)"",a,b,c" print *, "........................ STEPPER... After PRINT. Press Enter" read * print "(a,t10,a,tr2,a)",a,b,c print*,"print ""(a,t10,a,tr2,a)"",a,b,c" print *, "........................ STEPPER... After PRINT. Press Enter" read * print *, "........................ STEPPER... Before ENDPROGRAM. Press Enter" print*,"end program test2" read * end program test2

    23. 23 program tabular_output real, parameter :: third = 1.0 / 3.0 real :: x integer :: i do i = 1 , 10 x = i ! print "(f15.4, f15.4, f15.4)", x,sqrt(x),x**third print "(3f15.4)", x,sqrt(x),x**third end do end program tabular_output

    24. 24 program aa character (len=50) :: a, b, c, d, e integer :: i, j a = "aaa bbbb ccccc dddddd eeeeeee" print *, a i = index(a," ")+1 b = a(:i-2) print *, b c = a(i:) print *, c j = index (c," ") +1 d = c(:j-2) print *, d e = d(j:) print *, e end program aa

    25. 25

    26. 26

    27. 27

    28. 28

    29. 29 program aa character (len=50) :: a, b, c, d, e integer :: i, j a = "aaa bbbb ccccc dddddd eeeeeee" print *, a i = index(a," ")+1 b = a(:i-2) print *, b c = a(i:) print *, c j = index (c," ") +1 d = c(:j-2) print *, d e = d(j:) print *, e end program aa program 0206 ! Asks the hour and the minute values of the ! present time and displays it as a sentence. integer :: hh,mm print *, " Input the hour, in the 24 hours format." read *, hh print *, " Input the minute." read *, mm print *, "" print *, " THE TIME IS ",mm," MINUTES AFTER ",hh end program 0206 ! Assignment statements with constant expressions. program C01 implicit none integer, parameter :: NAME_LENGTH = 21 real :: Avogadros_Number integer :: Many complex :: Z logical :: Flag character (len = NAME_LENGTH) :: Name ! start program C01 Many = 346021 ! Integer type Avogadros_Number = 6.0221367e23 ! Real type Z = (0.0, 1.75e8) ! Complex type Flag = .true. Name = " Mustafa Sezer" ! Character type, length 21 write (unit = *, fmt = *) Many, Avogadros_Number, Z, Flag, Name stop end program C01

    30. 30 program C02 use C02M implicit none ! start program C02 call Assign_2( ) stop end program C02 ! Assignment statements with variable expressions. module C02M implicit none public :: Assign_2 contains subroutine Assign_2( ) ! Type declarations with initialization: real, save :: Y = 1.23, Pi = 3.141592 integer, save :: Counts = 173 character (len = 8), save :: I = " Optics " logical, save :: Flag = .true. ! Type declarations without initialization: real :: X, Theta integer :: Many character (len = 8) :: K logical :: Done ! start subroutine Assign_2 X = Y ! Real type Y = X Theta = Pi Many = Counts ! Integer type K = I ! Character type, length 8 Done = Flag ! Logical type write (unit = *, fmt = *) Y, Pi, X, Theta, Counts, Many, I, K, Flag, Done return end subroutine Assign_2 end module C02M ! Assignment statements with arithmetic expressions. program C03 implicit none real, parameter :: GRAVITY = 9.8 real :: Old_Vol, Old_Press, Old_Temp, New_Vol, New_Press, New_Temp real :: Mass, Velocity, Kinetic_Energy, Pressure, Density, Height, Bernoulli integer, parameter :: J = 6 integer :: I ! start program C03 I = J + 1 write (unit = *, fmt = *) I read (unit = *, fmt = *) Old_Vol, Old_Press, Old_Temp, New_Press, New_Temp New_Vol = Old_Vol * (Old_Press / New_Press) * (New_Temp / Old_Temp) write (unit = *, fmt = *) Old_Vol, Old_Press, Old_Temp, New_Vol, New_Press, New_Temp read (unit = *, fmt = *) Mass, Velocity Kinetic_Energy = 0.5 * Mass * Velocity ** 2 write (unit = *, fmt = *) Mass, Velocity, Kinetic_Energy read (unit = *, fmt = *) Pressure, Density, Velocity, Height Bernoulli = Pressure + Density * (0.5 * Velocity ** 2 + GRAVITY * Height) write (unit = *, fmt = *) Pressure, Density, Velocity, Height, Bernoulli stop end program C03

More Related