1.
Write a program to add two numbers
Input :
program addition
implicit none
integer:: a, b, s
print*, "Enter the first number: "
read*,a
print*, "Enter the second number: "
read*,b
s =a+ b
print*, "The sum of the two number is ", s
end program
Output:
Enter the first number
56
Enter the second number:
78
The sum of the two number is 134
2. Creation of 1-D array
Input:
program new
implicit none
integer, dimension (10) newarray
integer:: i
do i =1,10
newarray(i)=i
end do
print*, "The array is ", newarray
end program
Output:
2 3 4 5
The array is 1
6 7 8 9 10
3. Creation of 2-D array
Input:
program new
implicit none
: ; matrix
inte ger, d1'mension(2,2)
.
integer :: i,J
do i=1,2
do j=l, 2 . . .
matrix(i,J)=1*J
end do
end do
print*, "The matrix is
do i=l,2
print*,matrix(i,:)
end do
end program
Output:
The matrix is
1 2
2 4
4. Creation of 2-D array of Random Number
Input :
program matrix
implicit none
integer,dimension (3,3) :: a
integer :: i, j
print*, "Enter the elements of matrix A
do i = 1,3
do j = 1,3
read*, a(i,j)
end do
end do
print*, "The matrix A is
do i =1,3
print*, a (i,:)
end do
end program matrix
Output :
Enter the elements of matrix A
5
3
1
6
8
2
6
3
2
The matrix A is
s 3
6 1
8 2
6
3 2
S. Addition of two matrixes
Input:
program matrix
implicit none
integer,dimension (3 3 ) : : a, b, c
.
integer:: i, j ,
print*, "Enter the elements of matrix A
do i = 1,3
do j = 1,3
read*, a(i,j)
end do
end do
print*, "The matrix A is
do i =1,3
print*, a (i,:)
end do
print*, "Enter the elements of matrix B
do i = 1,3
do j = 1,3
read*, b(i,j)
end do
end do
print*, "The matrix Bis
do i = 1,3
print*,b(i,: )
end do
print*, "The Sum of the two matrix is
do i = 1,3
do j = 1,3
c(i,:) = a(i,:)+b(i,:)
end do
end do
print*, "The matrix C is
do i = 1,3
. *,c (.1,: )
print
end do
end program matrix
Output:
Enter the elements of matrix A
6
3
2
4
6
7
8
6
4
The matrix A is
6 3 2
4 6 7
8 6 4
Enter the elements of matrix B
1
2
3
5
6
4
3
2
3
The matrix Bis
1 2 3
5 6 4
3 2 3
The Sum of the two matrix is
The matrix C is:
7 5 5
9 12 11
11 8 7
6. Decission making statement in Fortran
Input :
program logic
impli cit none
intege r :: i
print* , "Enter the mark" ; read* ,i
if (1 .le, 30) then
print• , "You have failed the exam"
else if (i .ge, 60) then
print* , "You have passed the exam with good marks"
else
print* , "You have just passed the exam"
end if
end program logic
Output:
Enter the mark
S7
You have just passed the exam
7 , Write a FORTRAN to define the function s(x) such that
s(x) = 3 X>3
s(x) = x 3>= x >= -3
s(x) = - 3 X< -3
Input:
program function
.implicit none
integer : : x
print*, "Enter the value of x: "; read*, x
if (x .gt. 3) then
print*, "The value of S{x) 3"
else if (x .lt. -3) then
print*, "The value of S{x) -3"
else
print*, "S(x) = ", x
end if
end program function
output:
Enter the value of x
1
S(x) = 1.00000000
8. Write a FORTRAN to define the function s(x) such that
s(x) = 3 x>3
s(x) = x 3>= x >= -3
s(x) = - 3 x< -3
and Evaluate ((S(a) + S(b))/S(a+b)]
Input:
9. Factorial of a number
Input:
The roots are imaginary
11 . swaping of two numbers
Input :
program swap2
implicit none
real :: x, y, temp
print*, "enter the value of x
read*, x
print*, "enter the value of y
read*, y
print*, "before swaping: "
print*, "Value of x ", x
print*, "Value of y ", Y
call swap (x,y,temp) -temp = Ct
contains
subroutine swap(x,y,c) a. ~ b
implicit none
real :: x, y, c '6~ 1~
C = X
X = y
y = C
print*, "after swaping
print*, " Value of x , x
print*, "Value of y: ", y
end subroutine
end program swap2
Output:
enter the value of x
6
,. enter the value of y
8
before swaping
Value of x: 6.00000000
Value of y: 8.00000000
after swaping
Value of x 8.00000000
Value of y: 6.00000000
12. Opening and closing of a file
Input:
program addition
implicit none
integer, dimension (3,3) :: a, b, c
integer:: i, j
print*, "Enter the value of elemnts of the matrix - A
do i = 1, 3
do j = 1, 3
read*, a(i,j)
end do
end do
print*, "Enter the value of elemnts of the matrix - B
do i = 1, 3
do j = 1, 3
read*, b(i,j)
end do
end do
do i = 1,3
do j =1, 3
c(i,j) = a(i,j) + b(f,j) t111 1 1
end do
end do ,
l )
open(1,file='[Link]',status='new')
p
open (2, file= 'file. png', status=' new 1·, / l ,
open(3,file='[Link]',status='new)
write(1,*)'matrix a is'
do i= 1,3
write(l,*)(a(i,j), j =1,3)
end do
write(l,*)'matrix bis'
do i= 1,3
write(1,*)(b(i,j), j =1,3)
end do
write(1,*)'matrix c is'
do i= 1,3
write(l,*)(c(i,j), j =1,3)
end do
close(l)
end program addition
Output:
The file in pdf is
matrix a is
5 7 2
4 1 8
2 7 3
matrix bis
7 1 3
9 4 2
5 7 3
matrix c is
12 8 5
.,
13 s
14
10
6
13. Write a function to find the factorial. Hence evaluate p**2*(1 -q)/nl
Input:
program factorial
implicit none
real (kind= 16):: n, i, f, p, q, x, y
real : : z
print*, "Enter then number
read*, n
f = 1
do i = 1, n
f = f*i
end do
print*, "Factorial of", n, "is : ", f
print*, "Enter the value of p : \"
read*,p c 11 r
print*, "Enter the value of q: '\'
read*,q
X = p**2
y1-q=
z (x*y)/f
=
print*, "The value of the equation is•.z : : ", z ·
end program factorial
Output:
Enter then number:
s
Factorial of s.00000000000000000000000000000000000 is
120.000000000000000000000000000000000
Enter the value of p
4
Enter the value of q
6
The value of the equation is z ·: -0.666666687
14. Evaluate the above equation having Summation
Input:
program summation
implicit none
real (kind= 16)::s, a
r i nt eger :: p , q, n , i, f
---
print*, "Enter the value of P
read*,P "
print*, "Enter the value of q is: ..
read*,q upper limit for n of the denominator of the equation
print•, "Enter the
read•, n
do i = 0, n
f =1
if (i > 0) then
f = f*i
end if
a= (p**2 * (1 - q)) / f
s = 0.0
s = s + a
end do "
print*, "The result of the equation is: , s
end program summation
Output:
Enter the value of p
4
Enter the value of q
8
Enter the upper limit for n of the denominator , of the equation is :
6
The result of the equation is: -18.0000000000000000000000000000000000
15. Format Specification (1-D array formation)
Input:
program array
implicit none
real :: a, b, c, d, e
read*,a, b, c, d, e
print*, "The array is II
print 7,a, b, c, d, e
7 Format (F 5.2)
end program array
Output
1.234
34.123
67.233
23.67
12.34
The array is
-- .... -_,.. l/1'[Link]
. d d'.peaJ
II •
:JO an;e" a4~ .ia~u3,, '.[Link]
:J. f 'u 'b 'd :: Jaaaiu1
1.23
34.12
67.23
23.67
12.34
16. Format specification in exponential form
Input:
program array
implicit none
real :: a
read*,a
print*, "The array is
print 7,a
7 Format (E 9.3)
end program array
Output:
0.23E-10
The array is
0.230E-10
fo_,h,o n-
I I
1
I
- Fooi'l)OTl Known O.b fonr:nUlet. IMn-'i laFm8
SijS ~ em .i.;:i pc>O ~ OCI rn b () 8I IOA9uQ&e, ~e,d ' I
e)'.. ien ~jye,\~ ;o iu en w&· e,' , ood enSine ~t i'ri~ , , ,
· hon t
oppli~ 1 ," 11, , I,' ,1 \/,ii·1 ,- , 11 • , , ,
,
- Fotz TR AN 1,0,d ne. ·old e,c--1 YU Hhi 1eveL Ia0g u ~ &~ , I
uJUD [Link] in 11 /\q51
which ,,,,' 111 /ll\ >1 1:111
bu 1BH·
I . /10 11 Iii
.
.' I
\ ,,I
- \ZPLJ V I I ec
- u [Link] I :,1I
I
J( / I ( )
/
) ) ( J i( I J
1 r ,
' t 1 rI II J( : rI j I ,
o) q~ ti en\ u<l. . com pu+ati on01 r', ii / 1 11
rK1 rn e;is l
b) Suppoisb l ~cl [Link],xJ rlilCl\rf,n;iqhw.l ,, opec5o~on-
c.) A1>'clci.~ and 1m bk, Xi' )IQ pe11S Cl tl' or{(.,,. l, / I I I I
I I I
d) [Link] pzioff~'ei.'rlimi~g- -'> .1 1 , r, , / ,, ,,Ir,
e) p15obCtb't Ii \-8 1 I0. t.150 ~ r ICl \I&o1) r(i) ,I I 1/ I I , ( I I ii '', I
Si~l'tl&co~c'.e. ~ p~cJ'JAb~'d" r1I 1 ".1
11 11
' /rf)1 1'1 .·, 1.1 '
~A/ _.,@ern'e~4 '''thcd
_''rmpJdl :ndD{ \~l;l · F6~V
1
, I I
d'[Link],c imp~ c.i1 ~p,n~ ensu~in8 oJ\ va~'i'db'l~
rnl,lb\ be I ex'.plJdi \~ akct611£d'.,(1~ t8cU iD\-&6aU(e '
1
(. ot.\eo ro~1'RAN ' l1-/ 1, .,, [ (III Ji I • ,, JI/ ,, I:111111 ,/ ,, 11
~ 'ro~l(r 1RAN
l ·,: /, 1,11,
cu\
,,•1I L_1,1,1i,/
1n~ VO'ti\ 0 rJI~
11_ ·1, .. /1 /ii/I
- Upru :i::iJ
dec\ 0()Qd, w\1 n.1 \e·\''\ \:. u~ rn( l I , J \I L llAl O~ ,\J
J '\ , J -
ll N '. IM' l ii I' t\ (u., it) ,,~ue,,>, . V. e1>\ (' ..,, ~ \ ,-p_( A\<•,<\ (JI > ; ,
•\lw. G·locdi '"'~ poh, lo whith, cu.u 0ed n ,CJ , •~
\o~ k Ql e.ir1:io ~ ~ . 1
- 1t 1he. V0('.)[Link]~ b d~~i n~j le.S\ ~r1,[Link]>ed
lOt)')~\.ii\uh()n cm u~(}~, rnl'0u ~ ,w'il\ be, de plo~ed•
8
feo..¼uM?-<) ~'6 wa·,~ ng o, pD o81, q rn, in f ORTQ f-'\ N·
- i='o~TRAN ,lD ICt [Link]:i~,, ~e.n0'i \, ve la n8u%Q .,
1
\. Wn 'co
' n1 ' i' •: I I I ( ii }
o.. pto8oom , n on8' c.o llrnn .'
I I \ I ) \ ( ( I (
"-' Wt511e.
2· Mcoll mum. \12 [Link] d €25~ O<le. a l\owc\,(td I Iri o..
S.ln9B \ine, 1• 111 11, 11,, 1111 1, IJ , ,, 'Jr,, 1,r, ,, ,
1
?>- ' Fob <Of)tirk.1Ci.~m"' otr I C,tl ~i(r\e.,n~n\ 10 thQi r e)_-\
.U ne. and .S.~rnbo\ I ,JJ:\·,,f()e,d ;, Ji-\ oN~u fl\ f' ~ .
Con'tinuo. \i on~ Q~Q, e1.1io,41i<;l'i",, i ·,, , , ,, " \ 1
Li. WQ. c.q n we5'1-\e. mo~ei:\tha'll on~ 1c,:~\ .~f!r(?.nl i t;' ,
Cl
s)
IC'fj 'e line, ~e.p7~~1]~~ 1 ~ ~ ', ,~ ~ , to~.~~ ~ H,•., .
5. Com en\') c..cA n be. ~ dded ?(1 LIJ:)\nti 1 CU. -\~
', I ' rn /' I , Jr II ' Ji J/ IM I l I ) I{ I I I . .. , I .' I q I I I II I ' [I I I I
~~ ~1)F:, w I
{ II I ' I •I I I(, I I ' I " I I I II : I l /I II i ' ' I I I
I ' I,'/ I I II
6· Vo.~\Qb\Q
i I { I (ncr,oci
I i' I 11hu\lQ)
I ( ( I I
ma~m\ 10\I 11~hl~[Link].. \ ~ ~t~
. I / () i' l I ) )I J / I' • / •
, I
indud\na \e:H~b~, num \:)Q,~ ' ancl_unr\e~,~lOby ~-)
d · \r/(j / II · 1 r
~~ -~~1
1
I \
ond c1a~a~~ e ,
,~ m~ ,,,·ft
\
1~ :1,Qf~li t .
I( I I // ;l I / ) 1
( (
' I I ) ' ( 1 h 11 I I
1
\/ ( <1 ( 1 I , . i ,~ i , { , i
( J ',) ) nr I' .,\ t I I l J ,
.i ,I J J /) () ' i I I
I
, I
'I
, I I
.' .
,
.
I •
l ' 3 C l)
•
- i~ \ 03i t
u.l volt.,Q, '"6e r ~e
- s~ n\01'.
b e.,n \'rn ~ ·I /:,_ Je or,
I '
Lq)iml , ?0-~o 1R\JE
f ( \Q ,\ e,is
:: = ,\ '6ue. - I
~fi\l>t ::
I
e tWJ> Q. f I
I
Ill I
Q,) (,h{'lis~' c\l e , I I
I I I
' i I
' ' ·!
- ~ s\n\'0'6 I IIJ1 I I I
~r- c.,hMo.d et> Clef\"' Lt) · : . ~i.s 0 0 0
1
'I
t - r0e.. l 1 i
~
i)\~~'6Q,n\ ~ I
,~e.{:) JP ? ~ O . ~ 11
1 11
Q) f\1S\-\hrn<2.~ CIbp \(i\ i. FpR1
R~ N,
1e ' 6 0 ~ .1' .
: n JI J 1
111
foo p e ~ H l \ l n 1 , i /
11 1
~ ' mcd~e.'f
J:.~ :- t na~,~~ oP'J~
- odch\- I
CAtiof\.
io n , '
\ •1
1
7) r ,1 , :;..u •,s
,u't;i~;ti€.lt c\- .) • 11 , \ 111 •
i omil , 1v .\\. 'l
. ;K ,I
=- . rnu\ti\)Lir \
I, I,,,1
1
,•
o~on ,, /..
,,l l Ii' )\ r 11t,
JI1 , ,, : ; 11 t:
1 ci) v\~~9'0J 1 11
1 <11i
~ ;t:.
, 0 ,,i o n, , ,J \ ,
,
- expon~ r,)¼(~ '( i , \ I )/1
( )
I
, ( , 1 l' )
\
no t .ectu OvL
I'
- '
. f\~ •
\· o~ b·
-::.)
-,::.") ca-oe~-\ €,6 -\ nCt 'rt.
I I -
I ' _' .
' I
\ ~ -\n an
I I ia-oe.o1 el'.> -\ ho n o "6
\ '
I\ ,
-- I I \
e..q, ua..l bo ·
\\ l \ / 1\, \ 1'l \
c) J0 fj \col-: ~·pe1S o.\-o6 ,
I I j I I\ J I
I \ I I \
I I [
I ll ,1
I I ' \ d •
I I
t I I\ lr,
\
I
\I~ J \I I ' I I I
I , I lI I I l
I I I
l
I '
I
I
I, ,
} I
( I I ( I I
! ,I d 11! l / I~I I I I i' \ I
11 I[ )
I '
I
J I I I. /l I i lI ' I
' I
I
\
I l I ' ·( I \ i ( '( II l, I'
I
I • i/l il1 t' II /
l
\ I I I • II I I I ,, , , f l I I (1 \
iit l) /l
/ ,.• ,. ,,, , /'',~ \
) ., I ) ) I · \
I I ' ·1 I lI . / 1·
j I
. '
1 ., 1 ,I
I
I ltl , J/ i ' j
I
II
t
r~ecedentQ ~ ope,15 Cl\-u'6 I
Tn On ex.p-is~ion , OP,[Link]~~ w'i-\h h.J8heo f1llCl'Ji ~
wi II be. [Link]¼ed &;~ \: ·
'\
0 (\QtJ • (_ - )
E-x..ponenntltHYn
Mu\ \-i p\ ,~\i;v~. ~) I
AM,\;\J~ t J-
I
~e\o\ioncil
fciucw ~
109\Col liNi) · '
.lot\1wl. oR 1
~1<'d nr0 e.n \
t ~ .. e I\( . ~'' ( II C H K' n \.
i & l\o~\C ul. e_x. ~[Link]
) ·\hen
\ [Link]. ~o ex. e.t u\e i co t1 d b
• ·rn cm ·i.':i ·h UJ.
~\~e
\ toe\~ -\o ,e;[Link]-\~ \& cnn
• . di:hon --0 g(W)e
I . ' )
1
.
e r' (\ \ ~
'
II (I I I I
t) 1~ - [Link]. ib s\ulemQ.n\:
I
j ( I! .I I
\
i O' ( \ DfjkoJJ ''e ,~l) ~ fol1r \ \ \ ' ( Ir 1
,ir 1~~ ~I I ' ' ','' I (:
)'
' I l 'co de" ~ I etec1M,11 S¼h~e ~ e\,t ~ 1
, L~-! "bU€..
1r I
I I
e~e. it C. \03'i ci.U. ei,go~i i r,, · _c,
) ,{(I() ,' ) I2J )' )l➔hIen. .
oO
t [Link] . to e-x.e c'.u-\e. i ~ ~-\-o-\[Link] er ti • 1 R
(J ' l '1
.
l l I Al I i !\ I
rt ;- I .id o¾e.
I
Onu S 'l l
\ I~ (
(l l '_ii I
I I
Qrnern., -
1
(
1
1 ) ;
•l l
2 \~ n ~l U
,
e-I l' '
e\~e <\ 1c' r l 1) I : I/ J _t()'c\ I I ( I.~.
l cpd~ 10 e:x.e.w\e i& a.l \ tonc
en
. -
d 'u
t '' li'./1 I /11 :,, ,p /., 1d \.\ hoN o<'.le .BCUti<..
.. \ ll ll;/11111 1)1 I, I
. t)
.
Loop ~n \0 ~ ~ 1 AN :>:~~ )~~/\ /., 'l
• I,• ~
loop~ ClQpent CL s.e\: ~ . s\a
,",1i ·,1 11r1
I( • {
1
a
I. P , I r:1 1.. ,, , (ll , I 1, i;,,,,. ' 1.. ' , i,~'
., , ·,J • ; , • ,
r11
s.p~ ~Q.a \ernenb Goo 0- .
ru\l\ [Link] ab ·,\ e.~otioD~ . ? 1·'11, ii I I . ,I U
o ) Co ndihonol lcbpl I i 111 ,, , , 1"' /, · 1 1, ', , '\ ;i·
I ,,. , \;j
. . [Link]. I ~~~, ~ ~d~e ~~~t
~ ~ au e
1 -~·hi,~ I~ . J rd'i½oY\
~) , 1 ,, ) ·
I \ \
!I ! I( I' ' I I ,\ l ', 1
'.
, \ iI I 1
, 1
I( 11I I 1
I
I I I I j II I \
1 I '/ l )\ lIl ) \ ) \t f l
I. l,
I
,I I( I \ ( ,t .~ 1 I\ ()_ I (} l\ ,dil I. ., , 'i
\
\ ; I. I , (1 I
I t· \I 'i
I I I. I ~w1 \
t 1111\ ( ', : t ( { I ( .'I I } I
I. I
Sl lb p {'PU c"">l llH in ,~ ){) l U{~ 'UnN
f1 subp~o~lSurn .,U) ,n~Ul:)ub\ea
1hGt pe.D &~l'lrn~ Cl ~ pe. U&l c, \ c.u:i'" •
-1~peD oO ~bptC£j'IYOrn
o) Fu(\cJion I f I I I J
I '
- [Link]~ n~ o. ~ \n 8\e, vCLLu e_,
- ~d ~15 calculqhon 1\l' I 1 ,(
- C.a nno\- mod·,~ ex,\~n'cl ·1 vob\ClPleo 1
r
I I ' I I
1 II I
b)Su b-ootA tine,
\ I . '
l '
I
I ' •
I
'
'
I
,
U~:- , l , Il _. l (,I .i
0) To meet 1he n~edl 60° .1~er~e.o.{iecl UJoo~ \nu\de.
o.. pCJO~~om OnQ. wn' deoia'n CL JJb~b'03~arn
I ' I ( I {) { I I
b) Use. of7 ~ubp<5ogrom h~p:l ta ~<[Link]~·. Cc b,'d 1
CornpCJ~eo pM9norn ' '.Into s0CU! ':se,[Link]·
I I I '
I ' I I ' '\
/ I
... \. ~l,\'U 01C
. r· . l'\1nn ·, n t OVJ ~nN
\ O" u,(t ~ ... I
~cnD n. __ ,
_ /-,. . ,,on . .
.ti~\: 3v,J!J 1rde }Jo_t
n FORt--, n, (~\) ~). ) ~~ ) . ... )
\--\~e.,
Y\ ~ ~\u \ e.,[Link] nurn'oe}>
s,, ! ~l ~ I Ed,{ [Link]\ph)ts ~
\ 1.-\J ( I
Th~ .W1\\ -\-CLKQ. [Link]~~ \.a-1i·1ob\e. ct> -lhe,
II _I ~~~oil·,h-\nil READ l~ta\~me,n~ -
! I I ·, .\ I • I I\ I / I l I '
Ex..omn\e i 1,, , ,
'
1
I\ ( j I ( I: \ ( ' \ I' I \ j f
f-<[Link] , 5)
• l
Q \J1
11
'rnJ ,n.1 1 1 1
1i ,
1 , 11
1, I . 1 r I1 1 1
1 / 1
5 ~CY~rn()j:,1 1 ~ p 5 . 1)_
I
E .\)..•Lt) 1.5)
' I J,
'
I.
'
I
I
I
.
• ,, I l
I
Sp<2 ci &ctL\icin
1
~ ( ) ~ . DUfQbe_o 1".n f'9uc.,\ionCLL fo~rn
I\
Cod~~ r W•d
l .! I l ,
\ I \I' I !' ' I
1
P ., _ ' Tu<r, ~,~W, Dumb~ \'ri t"l'iuc\ionctl. ~-om
1
w -= iTn Qi nO, Ctr lO\Umlr\~ acw~ i~ ~ -\hQ.
1
\ .
f\L\°IT\0~15- 1 , l
I I l ~ \
d .-= . 1 DO· ob d\g"rb ei~\el> Mdrncll ~0\(1\, ·
E~·-- F 5 •2 ·
L_
-
r-;:
~ I'C \,I [~i((l Ii l) I\ di I I l I ( ff I. ,')
todQ, ~ 1w
1 ~ Tn~{:~Q,1>
Lu~ w\d1 h
E8:- I 5 I t
,SpQli 8cc,hon Ob zsen.L num9e1') 1n e1..pon~nhw tu~rr,_
CodQ. : E uJ•d ·1
E" ~e,al n c:.imb~-6 in 'e~~~~eltici...L ~ rn
I
1
w = -ki-\ul
I 1
wid\h oc.c'.J
p\ Jd ; 'b~' il-Q be?) n\Jm
d ~ n O· ob di 9'i\0 cippe.o1Sl"18 +o the, o i 8ht' ct;~he
1 1
detirnol po\n\ in -1hQ,' rnuhti.).)d.' pO<".lt · '
( , I 1' . :·1 ·· < ·
1 I 1 '1
t~:- E q:2, ~is' · b-2?.t :.:.10 ..· · · , )i
I
• ' i 'qp '·. 1110-i~O'Gl. \0 1'. ' .! I I' I I . I
; I ' ( J l,
d ' \ { I .' ' I II
I
, l ) ", , I l
} ) I ( I I I ''; I I I' ,I / f,. '
' I I 'l I l '. II ( Il . I
. \. . ,.·. : I . · 1'