0% found this document useful (0 votes)
44 views11 pages

Baskom 1 Format Input Output

The document contains examples of using different Fortran formats to output numeric values. It shows formatting integers, reals, exponents, and characters in various width and precision specifications. It provides examples formatting single values and arrays. It also demonstrates opening and writing to files in Fortran.

Uploaded by

zxcvhj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views11 pages

Baskom 1 Format Input Output

The document contains examples of using different Fortran formats to output numeric values. It shows formatting integers, reals, exponents, and characters in various width and precision specifications. It provides examples formatting single values and arrays. It also demonstrates opening and writing to files in Fortran.

Uploaded by

zxcvhj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

WRITE(*,4)

4 FORMAT(1X,HASIL UJIAN)
1 2 3 4 5 6 7 8 9 10 11 12
A H L S U I J
A
I N
CONTOH FORMAT KARAKTER
JUM = 12
MEAN = -14
N = -146
WRITE(*,30) JUM, MEAN,N
30 FORMAT(1X,I3,2X,I3,2X,I4)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 - 4 1
1
4 -
6
CONTOH FORMAT INTEGER
WAKTU = 3.184
WRITE(*,10) WAKTU
10 FORMAT(1X, WAKTU=,F5.2)
1 2 3 4 5 6 7 8 9 10 11 12
A W U K . 3
1
T 8 =
CONTOH FORMAT KARAKTER DAN
REAL DG FORMAT F

X1 = 0.00143
WRITE(*,30) X1
30 FORMAT(1X,X1=,E10.3)
X 1 = 0 . 1 4 3 E - 0 2
1 2 3 4 5 6 7 8 9 10
CONTOH FORMAT KARAKTER DAN
REAL DG FORMAT E

REAL*4 g, h, e, r, k, i, n
DATA g /12345.678/, h /12345678./, e /-4.56E+1/, r/-365./
WRITE (*, 100) g, h, e, r
100 FORMAT (1X, F8.2)
WRITE (*, 200) g, h, e, r
200 FORMAT (1X, 4F10.1)


Program diatas menghasilkan output sbb:

12345.68
********
-45.60
-365.00
12345.712345680.0 -45.6 -365.0


INTEGER n, order, alpha, list(100)
REAL coef(4), eps(2), pi(5), x(5,5)
CHARACTER*12 help
COMPLEX*8 cstuff

DATA n /0/, order /3/
DATA alpha /'A'/
DATA coef /1.0, 2*3.0, 1.0/, eps(1) /.00001/
DATA cstuff /(-1.0, -1.0)/

C The next statement initializes diagonal and below in
C a 5x5 matrix:
DATA ((x(j,i), i=1,j), j=1,5) / 15*1.0 /
DATA pi / 5*3.14159 /
DATA list / 100*0 /
DATA help(1:4), help(5:8), help(9:12) /3*'HELP'/


C Generate a table of square and cube roots
C of the whole numbers from 1-100
WRITE (*, 10) (n, SQRT(FLOAT(n)), FLOAT(n)**(1.0/3.0),
+n = 1, 100)
10 FORMAT (I5, F8.4, F8.5)


cc The following example opens a new file:
C Prompt user for a file name and read it:
CHARACTER*64 filename
WRITE (*, '(A\)') ' enter file name '
READ (*, '(A)') filename
C Open the file for formatted sequential access as unit 7.
C Note that the specified access need not have been specified,
C since it is the default (as is "formatted").
OPEN (7, FILE = filename, ACCESS = 'SEQUENTIAL',
+ STATUS = 'NEW')

cc The following example opens an existing file called DATA3.TXT:
C Open a file created by an editor, "DATA3.TXT", as unit 3:
OPEN (3, FILE = 'DATA3.TXT')

Tulislah hasilnya jika bilangan ditulis dalam FORMAT sbb.
Bilangan .00176
FORMAT E10.2
Bilangan 529
FORMAT I4
Bilangan -84
FORMAT I2
Bilangan 1263.05
FORMAT F8.1
Bilangan -3.8
FORMAT F4.2
Tulislah hasilnya jika bilangan ditulis dalam FORMAT sbb.
Bilangan .00954
FORMAT E12.3
Bilangan 6713
FORMAT I5
Bilangan -125
FORMAT I3
Bilangan 2174.05
FORMAT F9.2
Bilangan -2.7
FORMAT F6.2
Tulislah hasilnya jika bilangan ditulis dalam FORMAT sbb.
Bilangan .005371
FORMAT E15.6
Bilangan 257
FORMAT I5
Bilangan -59
FORMAT I2
Bilangan 3406.45
FORMAT F10.3
Bilangan -6.94
FORMAT F5.3

You might also like