




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Download the solutions manual for Classical Fortran Programming for Engineering and Scientific Applications, Second Edition by Michael Kupferschmid. Essential for 2025/2026 engineering, physics, and computational science students covering Fortran programming, numerical methods, and scientific computing.
Typology: Exams
1 / 280
This page cannot be seen from the preview
Don't miss anything!





























































































e is m ic i s o la ti o n
1 AboutkThiskSolutionskManual 1
1.1 TokthekStudent .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k.
1.2 TokthekInstructork k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k.
2 SolutionsktokthekExercises 3
Chapterk 1 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 2 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 3 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 4 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 5 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 6 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 7 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 8 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 9 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 10 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 11 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 12 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 13 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 14 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 15 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 16 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
Chapterk 17 .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k .k
.k .k .k .k .k.
3 Extrak Exercisesk andk Theirk Solutions 221
4 Teachingk FORTRANk Programming 259
e is m ic i s o la ti o n
1
Thisk Solutionsk Manualk isk intendedk fork thek instructorkofk ak coursekthatk usesk Classicalk FORTRAN
askaktextbook,kandkforkthekstudentkwhokisklearningktheksubjectkindependently.
Ifkyoukarekakstudentktakingkthekcoursekforkcreditkyoukshouldkknowkthatkitkiskakviol
ationk ofkacademickethicskforkyouktokconsultkthisk SolutionskManual,k whetherkyoukcopykve
rbatimkfromkitkorkonlykusekitktokgetkideaskaboutkhowktokworkkthekexercises.k Thekexercis
eskarekakvaluablekaidktoklearningkthekmaterialkinkthektextbook,kbutkonlykifkyoukworkkthe
mk yourselfk !kLookingkupkthekanswerskinsteadkofkfiguringkthemkoutkdepriveskyoukofkankop
portunityktoklearnkthekmaterial.k Ifkankanswerkiskforkcredit,kcheatingkiskalsokpersonallykde
gradingktokyoukandkunfairk tok yourk classmates,kandk itk mightk placek youk ink jeopardykofk d
isciplinarykaction.k Ifk thiskiskankillicitkcopy,kpleasekdestroykitknow.k Ifkthiskiskakstolenkcopy,
kpleasekreturnkitktokitskrightfulkowner.k Eitherkway,kSTOPkREADING.
Ifkyoukarekakstudentklearningktheksubjectkbykyourselfkthenkyoukarekyourkownkinstruc-
tor.k Pleasekreadktheknextksection.
Thisk Solutionsk Manualk isk intendedk fork thek instructorkofk ak coursekthatk usesk Classicalk FORTRAN
askaktextbook,kandkforkthekstudentkwhokisklearningktheksubjectkindependently.
Ifkyoukarekinkeitherkcategorykyoukshouldkknowkthatkitkgreatlykdiminisheskthekusefulnes
skofkthekexerciseskforkgradedkworkkifktheirksolutionskbecomekpublic.k Pleasekrefrainkfromk
loaningkthiskbookktokothers,kdistributingksolutionsktokothers,korkpostingksolutionskonkthek
WorldkWidekWeb.k Ifkyoukwantktokshowkakgroupkhowktoksolvekakproblem,kIksuggestkmaki
ngkaktransparencykork scanningk tok ak.pdfkfilek fork projection,k ork postingk thek solutionk i
nk ak displaykcasekunderkglass,ksokasktokrevealkthekanswerkwhilekdiscouragingkphotocopyin
gkorkelectronickscanning.
Atktheksamektime,kitkiskprudentkforkinstructorsktokexpectkthatksomekstudentskwillkhave
kaccessktoktheksolutionskandkthuskankunfairkadvantagekoverktheirkclassmateskwhokdoknot.
k Ifkyouksuspectkthiskmightkbekthekcase,kyoukshouldkconsiderkassigningktextbookkexercises
kwhoseksolutionskarek notk includedkinkthisk Manualk orkmakingkupkproblemskofkyourkown,k
perhapskmodeledkonkexerciseskinkthektextbook.
Chapterk 2 kofkthisk Manualk providesksolutionsktokaboutkhalfkofkthekexerciseskinkthektext,
kdistributedkinksuchkakwaykasktokrepresentkeachkproblemktypekinkeachkchapterkwhilekfav
oringkeasykproblemskandkearlykchapters.k Chapterk 3 kofkthisk Manualk containsksomekadditi
onalkexerciseskandk theirk solutions.k Chapterk 4 k containsk somek materialsk thatkIkhavek fou
ndk usefulkink teachingkprogrammingkfromk Classicalk FORTRAN.
e is m ic i s o la ti o n
⌈k k ×k
k ⌉
2
Eachksolutionkincludeskmykroughkestimatekofkhowkdifficultkthekexercisekis.k Easykprobl
ems,kmarkedk[E],ktestkthekstudent’skrecallkofkfactskandkconceptskdiscussedkinkthekt
ext.k Hardkproblems,kmarkedk[H],kneedksomekindependentkthoughtkandkpossiblyksome
kprogrammingkbutkusuallykdoknotkexplicitlykrequirekthekstudentktokdeliverkakprogram.
k Projects,kmarkedk[P],ktypicallykaskkforkakfinishedkprogramkaskpartkofktheksolutionktokt
hekexercise,kandkinkmostkcaseskprovidingkonekrequireskanalysis,kprogramkdesign,kandkd
ebuggingkaskwellkaskcodingkinkFORTRAN.k Thekfractionkofksolutionskpresentedkherekvarieskfr
omkonekpartkofkthektextbookktokanotherkandkbykproblemkdifficulty,kaccordingktokthektab
lekbelow.
partk(seek§0.5.3) [E]k easy [H]khard [P]k project
INSPIRATION none none none
ELEMENTARY all
1
2
1
3
INTERMEDIATE
1
2
1
3
1
4
ADVANCED
1
3
1
4
1
5
REFERENCE none none none
Thekpartskofkthekbookkthatkareklistedkinkthekleftkcolumnkarekthosekidentifiedkinkthektablekof
0.5.3kinkthektext.kThekactualknumberkofksolutionskprovidedkforkeachkchapterkandkdiffi
cultyklevelkisk nk fk ,kwherek nk isktheknumberkofkproblemskhavingkthatkdifficultykinkthe
kchapterkandk fk iskthekfractionksolvedkofkthatkdifficultykinkthekpartkofkthekbookktokwhi
chkthekchapterkbelongs.k Applyingk thek formulakyieldskthek distributionk ofksolutionskshownki
nk thek tablek onktheknextkpage.
Manykofktheksolutionskprovidekakmorekthoroughkdiscussionkofkthekproblemkthankonek
mightkexpectkfromkakstudent,kakfewkreferkincidentallyktoktextksectionskthatkthekstudentkne
edknotkhavekreadkyet,kandksomekofkthekprojectskareksufficientlykopen-
endedkthatkmanykdifferentk“answers”kcouldkbekconsideredkcorrect.kThus,ktheseksolutionsk
arekmeantktokenlightenkthekgraderkratherkthanktokservekaskstrictktemplateskagainstkwhich
kstudentkworkkiskdirectlykcompared.
Becausekeachksolutionkiskself-
contained,kliteraturekcitationskinkthisk Manualk arekgivenkwithinkeachksolutionkratherkthankb
eingkcollectedkinkakbibliography.kSectionkreferenceskappearingkinktheksolutionskarekto
ksectionskinkthektextbook,knotktoksectionskofkthisk Manual.k Outputkformattingkinkthekte
rminalksessionkexcerptskvarieskslightlykdependingkonkthekUNIX
TM ksystemk (Sun,kIBM,kSGI,kor
kLinux)kthatkIkusedktokrunkeachkprogram.
Ifk youk needk ak solutionk thatk wask notk selectedk fork inclusionk here,k pleasek contactk thek a
uthorkbyksendingkemailktokmikek@rpi.edukorkpaperkmailktokPOkBoxk215,kCropseyville,k
NYk12052.
e is m ic i s o la ti o n
4 ClassicalkFORTRANk SolutionskManual
part chapter easy hard project total
given done given done given done given done
totals 321 183 167 60 89 30 577 268
e is m ic i s o la ti o n
Solutionsk tok thek Exercises 5
1.5.1 [E]k (a)k Thek syntaxk ofk ak programmingk languagek isk thek setk ofk rulesk prescribingk
howkitsksymbolskmaykbekassembledktokformkmeaningfulkstatements.k (b)kTheksemanticsk
ofkakprogrammingklanguagekarekthekruleskdescribingkwhatkmeaningkattachesktokeachksynt
actically-kcorrectkstatement.k (c)kSourcekcodekiskhuman-
readablektextkconsistingkofkcommentskandksyntactically-
correctkstatementskinksomekprogrammingklanguage.k (d)kObjectkcodekiskaksequencekofkm
achine-
readableksymbols,kusuallyknotkcorrespondingktokprintablekcharacters,krepresentingkthekm
achinekinstructionskthatkresultkfromktranslatingkaksourcekprogramkforkakparticularkprocess
or.k (e)kLinkagekeditingkiskthekprocesskofkconcatenatingkthekobjectkcodekforkthekvariousk
routineskofkakprogram,kincludingkuser-
written,klibrary,kandksystemksubprograms,kandkfillingkinktheirk(relative)kstartingkaddresses
kwhereverkthosekmightkbekrequiredktokresolvekreferencesk byk eachk routinek tok thek othe
rsk makingk upk thek program.k (f)k Ank executablek iskakconcatenationkofkobjectkmodulesk
withkallkofkthekcrossreferenceskresolved,kcompletekandkreadyktokbekloadedkintokthekmem
orykofkakcomputerkwherekitkcankbekbranchedktokinkorderktokrunkthekcompiledkprogram.
1.5.2 [E]kInkthiskbookk(accordingktok 1.1)kthekfollowingkcharacterksetkiskusedkinkFORTRAN
statements.
ABCDEFGHIJKLMNOPQRSTUVWXYZk
Theklower-
casekalphabetickcharacters,kandkoccasionallykotherkcharacters,karekalsokusedkinkFORTRAN
k commentsk inkthektextbook.k Theksemicolonk;kiskusedkaskthekcontinuationkcharacterkink t
hek textbook.k Thek underscorekcharacterk k isk mentionedk ink 13.2.2kandk appearskink 16.
kinktheknameskofkMPIkroutineskandkvariables.k Ink 13.6.1,kthekampersandkcharacterk&kisk
mentioned.
1.5.3 [E]kClassicalk FORTRANk usesk fixedk sourcek form,k ink whichk statementsk begink ink o
rk tokthekrightkofkcolumnk 7 kandkextendkonlykthroughkcolumnk72.k Therefore,kblankskareksi
gnificantkinkcolumnsk 1 -
6 kofkeachkstatementkandkmayknotkbekomitted,kandkblankskusedkforkindentationkmustk no
tk pushk thek textk ofk ak statementk pastk columnk 72 k (butk seek 13.1.3).k Ask discussedk ink10,
kblankskmaykoccurkinkcharacterkstringskandktheykarekthenksignificantkaskdata.k Otherwise,
kblankskmaykbekinsertedkorkomittedkatkthekprogrammer’skoption.k Thus,kforkexample,kthe
kfollowingkprogramskarekregardedkaskequivalentkbykthekg77kcompiler.
A=3.14 AAk =k 3 k.k 1 k 4
B=4.753 BBk =k 4 k.k 7 k 5 k 3
C=SQRT(A2+B2)
Ck =k Sk Qk Rk Tk(kAk Ak *k *k 2 k +k Bk Bk *
k k 2 k)kPRINT,C Pk RkIkNk Tk *k,kC
STOP Sk Tk Ok P
END Ek Nk D
Advicekiskgivenkink 12.4.5kaboutkhowkmuchkwhitekspacektokusekwhereksokthatkyourkprogr
e is m ic i s o la ti o n
6 ClassicalkFORTRANk SolutionskManual
1.5.4 [E]kAccordingktok 1.1,k(a)kakcommentkiskanyksourceklinekthatkhaskakCkinkcolum
nk 1 kandk(b)kakstatementkmustkappearkinkcolumnsk 1 -
72.k(c)kAnyktextkextendingkbeyondkcolumnk 72 kiskignoredkbykthekcompiler.k(d)kAkcom
mentkcankbekcontinuedkonlykbykinsertingkanotherkcommentkline.k(e)kAkstatementkcan
kbeginkinkcolumnk8,korkinkanykotherkcolumnktokthekrightkofkcolumnk7,kasklongkaskitke
ndskbeforekcolumnk73.
1.5.5 [E]k Eachk commentk linek ink ak Classicalk FORTRANk programk hask ak Ck ink columnk 1,
k andkiskignoredkbykthekcompiler.k Commentskcankbekcontinuedkonlykbykinsertingkanotherk
commentkline.k Inkthiskbook,kcommentskarekwrittenkusingkmixedkcase.
EachkstatementklinekinkakClassicalkFORTRANkprogramkbeginskinkorktokthekrightkofkcolumn
7 kandkendskinkorkbeforekcolumnk72.k ItkmustkbekconstructedkaccordingktokthekruleskofkF
ORTRANksyntax,kandkisktranslatedkbykthekcompiler.k Statementskcankbekcontinuedkbykplac
ingkaknonblankkcharacterkotherkthank 0 kinkcolumnk 6 kofkeachkcontinuationklinek(seek 13.1.
8).k Ink thiskbook,kstatementskarekwrittenkusingkupperk casekletters,kandkthekcontinuationk
characterk isk;.
Ankexecutablekstatementkgenerateskmachinekinstructionskthatkarekexecutedkatkrunktime,
afterkcontrolkisktransferredkbykthekoperatingksystemktokthekexecutablekprogram.
Thek non-
executablek statementsk ofk ak programk providek thek compilerk withk informationkaboutk thek
sourcek textk (e.g.,k ENDk marksk thek endk ofk thek sourcek fork eachk routine)k ork aboutkthek da
tak structuresk thatk willk bek usedk byk thek programk (e.g.,k COMMONk statementsk describekth
eklayoutkofksharedkdatakareas,kaskexplainedkink 8).kNon-
executablekstatementsk(e.g.,ktypekdeclarations)k cank affectk thek machinek codek thatk isk gener
atedk fork executablek statements,k ork(e.g.,kcompile-
timekinitializations)kcankcausekthekgenerationkofkmachinekcodekthatkstoreskdatakwhenkthek pr
ogramkisk loadedkintok memory.
1.5.6 [E]kThekthreekstatementskintroducedkinkthiskchapterkarekPRINT,kSTOP,kandkEND.kT
hekPRINTkstatementkcankbekusedktokprintktextkork(askwekshallkseeklater)kthekvalueskofkva
riables.kThekSTOPkstatementkiskexecutable,kandkreturnskcontrolkofkthekprocessorktoktheko
peratingksystem.k ThekENDkstatementkisknon-
executable,kandkmarkskthekendkofkeachkroutine’sksourcektext.
1.5.7 [E]kTokbeginkrunningkyourkprogram,kthekoperatingksystemkcopieskyourkexecuta
blekintokmemorykandktransferskcontrolktokitskfirstkmachinekinstruction.kWhenkyourkpr
ogramkiskfinishedkitkexecuteskakSTOPkstatementktokreturnkcontrolkofkthekprocessorktok
thekoperatingksystem.k Ak programk cank containk anyk numberk ofk STOPk statementsk (thoughk
itk makesk sensek andkisk syntacticallyklegalktok havekmorek thank onek onlykifk thek programkhask
morek thank onek possiblekpathkforkthekflowkofkcontrol,kaskexplainedkink 3).k Inkcontrast,k
ENDkisktheklastkstatementkofktheksourcektextkofkakroutinekandkisknotkexecutable.kInkakf
ilekcontainingkseveralkroutines,kthekENDkstatementskshowkthekcompilerkwherekonekro
utinekendskandktheknextkbeginsk(thiskcankhappenkwhenkakprogramkconsistskofkseveralk
routines,kaskexplainedkink§6).
1.5.8 [E]kClassicalkFORTRANkiskakratherklow-
levelklanguage,kbutkitkiskeasierktokwritekthankassemblerklanguagekandk muchk easierkto
kwritekthankmachineklanguage.k Ankassembler-korkmachine-
languagekprogramkcankbekusedkonlykonkprocessorskhavingkakparticularkinstructionkset,k
butkakFORTRANkprogramkcankbekusedkonkanykcomputerkthatkhaskakFORTRANkcompiler
e is m ic i s o la ti o n
SolutionsktokthekExercises 7
1.5.9 [E]kAccordingktok1.2,kthekcompiler’sktwokmainktaskskarektranslatingkFORTRANkso
urcekcodekintokmachinekinstructionskandklinkingkinkanykoperatingksystemkroutineskus
edkbykthekprogram.k Askwekshallkseeklaterkitkiskalsokpossiblekforkakprogramktokbekma
dekupkofkseveralkroutines,kandktokusekroutineskstoredkinkaksubprogramklibrary,kandkin
kthatkcasektheklinkagekeditingkstepkperformedkbykthekcompilerkcombineskallkofkthekpa
rtsktokmakekankexecutable.
1.5.10 [E]kIfkakClassicalkFORTRANksourcekprogramkiskinkthekfileksource.f,kwekcouldkco
mpilekandkrunkitkbykusingkUNIX
TM kcommandsksimilarktokthese.
unix[1]kf77ksource.fku
nix[2]k a.out
1.5.12 [E]kAnkexecutablekpreparedkforkonekcomputerkcankbekrunkonkanotherkonlykifkthe
kprocessorskofkthektwokmachineskbothkusektheksameksetkofkmachinekinstructions,kbecaus
ekthekobjectkcodekinkankexecutablekconsistskofkmachinekinstructionskforkthekprocessorkof
kthekcom-
kputerkwherekthekprogramkwaskcompiled.k Evenkifkthekprocessorskarektheksame,kthekexecu
tablekwon’tkrunkonktheksecondkcomputerkifkthekcomputerskhavekdifferentksystemkroutine
s,kwhichktheykprobablykwillkunlesskthek operatingksystemskarekidenticalkversionskofkUNIX
TM .k TokmovekakFORTRANkprogramkfromkonekmachinektokanotherkofkakdifferentkkindkitkis
kusuallyknecessaryktokrecompilekthekprogramk(thatkis,ktranslatektheksourcektokmachinekla
nguagekandklinkkinktheksystemkroutines)konktheknewkmachine.
1.5.13 [H]kAskIkwritekupkthisksolution,kmykcomputerkiskakPCkrunningkLinux.k Ikused
kthekviktextkeditorktoktypekthektextkofkthekprogramkintokakfileknamedkhello.f,kchan
gingkthekprogrammer’sknamektokmykown.k ThenkIkfollowedktheksamplekterminalksessi
onkink 1.3ktokcompilekthekprogramkandkrunkit,kaskshownkbykthekfollowingkconversatio
n.
mike[1243]k vik hello.
fkmike[1244]kmorekhell
o.fkC
CodekbykMichaelkKupferschmi
dkC
C
Thiskprogramksayskhell
o.kC
PRINTk*,’Hello,kworld!’
kSTOP
END
mike[1245]kg77khello.f
kmike[1246]ka.outkH
ello,k world!kmike[
47]
MykUNIX
TM kpromptkiskmykloginkname,kwhichkiskmike,kfollowedkbykakcommandknumb
erkinksquarekbrackets.kIkhadkbeenkusingkmykmachinekforkakwhilekonkthekdaykthatkIkdi
dkthis,kandkthekcommandknumberkhadkreachedk 1243 kwhenkIkbegan.kTokshowkwhatkIke
nteredkinkthekfilekusingkvi,kIkusedkthekUNIX
TM kmorekcommandktoklistkitskcontents.k T
heknamekofkthekLinuxkcompilerkiskg77,ksokIkusedkthatktokcompilekthekprogram.k Then
kIkenteredktheknamekofkthekexecutablekproducedkbykthekcompiler,ka.out,ktokrunkthe
kprogram.
e is m ic i s o la ti o n
2
Solutionsk tok thek Exercises 9
2.9.1 [E]kThekonlykstatementskthatkcankbekinterchangedkinkthekhypotenusekprogramkwit
houtkaffectingkitskresultskarekthekassignmentsktokAkandkB.
2.9.2 [E]k Thek FORTRANk variablek GODk isk real,k becausek itk doesk notk begink withk I,k J,
k K,k L,kM,korkN.kWhetherkGodkiskrealkiskbeyondkthekscopekofkthisktext;kyoukwillkhavektok
decidekforkyourself.
2.9.3 [E]kItkisknotknecessarykforkthekvaluekofkakFORTRANkvariablektokchangekduringk
thekexecutionkofkakprogram;kitkcankretainktheksamekvaluekthroughoutkthekcalculation.kF
ORTRANkconsiderskvariableskbeginningkwithkthekletterskI,kJ,kK,kL,kM,kandkNktokbekinteg
erskbykdefault.kAkspacekisknotkaklegalkcharacterkinkakvariablekname,ksokvariableskcannot
khaveknamesksuchkaskITEMkAk(butkseekExercisesk1.5.3kandk3.8.13).k Itkisklegalktokusekt
heksamekvariableknamekforkmorekthankonekquantity,kbutkaskwekshallkseekink§12.4.2kt
hatkiskusuallyknotkakgoodkidea.
2.9.4 [E]k(a)k[ e
1 ]
(^3). 2 k=k e
(^1) × (^3). 2 k=k e
(^3). 2 ksokthekexpressionkcankbekrewrittenkEXP(3.2).k T
heknumericalkvaluekofkEXP(3.2)kisk24.5325317,ksokthekexpressionkcouldkinsteadksi
mplykbekreplacedkbykthatknumber.k(b)k[ e
(^3). 2 ]
(^3). 2 k=k e
(^3). (^2) × (^3). 2 k=k e
(^3). 2 k sokthekexpressionkca
nkbekrewrittenkEXP(3.2**2)korkreplacedkbyk28001.1465,kwhichkiskitsknumericalkvalue.
k (c)k 3_._ 2
2 k=k 10_._ 24,ksokEXP(3.2**2)kcank ink turnk bek rewrittenk EXP(10.24)k ork replacedk
byk 28001.1465k ask ink (b).
(d)k e
ln k
(A) k=k Ak andk e
ln k
(B) k=k B ,ksokEXP(ALOG(A)+ALOG(B))kcankbekreplacedkbykA*B.
2.9.5 [H]kItkisktokbekshownkthatkI/J/K/L=I/(JKL)kevenkthoughkintegerkdivisionktr
un-kcates.kThekfollowingkproofkiskduektokM.kS.kKrishnamoorthy.
Ink numberk theory,k truncationk isk justk thek “floor”k operation,k ⌊ a,kb ⌋,k yieldingk thek smallestk
inte-
kgerknotklesskthankthekrealkquotientk a/b .k Thuskitksufficesktokprovekthatk⌊⌊ x,ki ⌋ ,kj ⌋k=k⌊ x,k
( ik ×k j )⌋.
Letk xk =k pk ×k ik +k q,k 0 k≤k qkk 0,kwekcankmultiplykthruktheksecondkinequalitykabovektokobtaink 0 k≤k sk ×k ik
_
e is m ic i s o la ti o n
⌊ x,k ( ik ×k j )⌋k=k r ,kwhichkcompleteskthekproof.k ✷
e is m ic i s o la ti o n
Solutionsk tok thek Exercises 11
2.9.6 [E]kAkmathematicalkequationkexpresseskakpermanentkrelationshipkbetweenkseveral
kquantities.k AkFORTRANkassignmentkstatementkiskankorderktokreplacekthekcontentskofkth
ekstorageklocationknamedkbykthekvariablekonkthekleftkofkthek=kwithktheknumericalkresultk
ofkperformingkthekcalculationkindicatedkonkthekrightkofkthek=.
2.9.7 [E]kSomekinterpretationkisknecessaryktokdecidekwhatkitkmeansktok“correct”keac
hkofkthesekstatements.k Thekintentkofkthekfirstkonekiskevidentlyktokgivek-
Jkthekvaluek5,kwhichkisktheksamekaskassigningkJkthekvaluek-
5.kTheksecondkstatementkassertskakrelationshipkbetweenkX,kA,kB,kandkC.kAssumingkthat
kX,kA,kandkBkarekknown,kwekcankrewritekitktoksolvekforkC.
J=- 5
C=-AX2-BX
IfkwekassumekinsteadkthatkX,kA,kandkCkarekknown,kandkthatkXkisknonzero,kwekcankturnkth
eksecondkstatementkintokankassignmentkbykrewritingkitktoksolvekforkB.
B=(-AX*2-C)/X
IfkwekassumekinsteadkthatkA,kB,kandkCkarekknown,kandkthatkAkisknonzero,kwekcankturnkt
heksecondkstatementkintokankassignmentkbykusingkthekquadratickformulaktoksolvekforkX.k
Wekalsokhavektokmakekankassumptionkaboutkwhichkrootkiskdesired.k Ifkwekwantkthekposit
ivekone,kwekgetkthekfirstkstatementkbelow;kifkwekwantktheknegativekone,kwekgetktheksec
ond.
X1=(-B+SQRT(B2-4.AC))/(2.*A)
X2=(-B-SQRT(B2-4.AC))/(2.*A)
2.9.8 [E]kTheksecondkstatementkisklonger,kbutkbothkhavekexactlyktheksamekeffect.k Anykc
ompetentkcompilerkgenerateskidenticalkmachinekcodekforkbothkstatements.
2.9.9 [E]kThekprogramkonkthekleftkbelowkevaluateskthekexpressionskasktheykarekgivenkink
thekquestion.k Thekprogramkonkthekrightkuseskparenthesesktokindicatekthekorderkofkopera
tionskresultingkfromkthekprecedencekrules.
I=7 I=
X=3. X=3.
I=I+1/I- 3 I=I+(1/I)- 3
X=X/(X-1.)2(-1)-1. X=(X/((X-1.)(2(-1))))-1.
PRINTk,I,X PRINTk,I,X
STOP STOP
END END
Ifkeitherkprogramkiskcompiledkandkrunkitkproduceskthekoutputkshownkbelow.
4 k k 2.
However,k itk shouldk bek possiblek fork thek studentk tok reasonk outk thek answersk beforek condu
ctingkthekexperiment,k askfollows.k (a)k Inkthek formulakforkI,kthek operationkwithk highestkprece
dencekiskthekdivisionkandk1/7kyieldsk0.kThenk7+0-
3 kgiveskI=4.k(b)kThekexpressionk2**(-
1)kreducesktok1/2,kwhichkyieldsk 0 kbecausekintegerkdivisionktruncates.k Thenk(X-
1.)**0kisk1.,kandk(3./1.)-1.kgiveskX=2.
e is m ic i s o la ti o n
12 ClassicalkFORTRANk SolutionskManual
2.9.10 [E]kBlankskinkcolumnsk 7 -
72 kofkakFORTRANkstatementkareknotksignificantkexceptkinkcharacterkstrings,k sok thek state
mentk Yk =kSINk Xk iskinterpretedkaskY=SINX,kandkthek variablekSINXkiskneverkgivenkakvalue
kbykthekprogram.k Inksomekoperatingksystemkenvironmentskthekmemorykallocatedkforkakp
rogram’skdatakiskinitializedktokzeros,kandkinkthatkcasekthekgivenkprogramkwouldkprintkakz
ero.k Inkotherkoperatingksystemkenvironmentskuninitializedkvariableskcankhavekanykvalue,k
andkinkthatkcasekthekoutputkiskunpredictable.k Tokprintktheksinekofk 1 kradian,kthekstateme
ntkmustkbekrecodedkYk=kSIN(X).
2.9.11 [E]kHerekiskthekprogramkrewrittenktokpromptkforkAkandkBkbeforekreadingkthem.
PRINTk*,’A=
’kREADk *,Ak
PRINTk*,’B=
’kREADk *,B
HYP=SQRT(A2k +k B2)k
PRINTk *,’HYP=’,HYPkST
OP
END
e is m ic i s o la ti o n
heksidekofklengthk a ),kthenk B ,kthenk C ,kandkthekuserkmustkknowkthisktokproperlykinterp
retkthekoutput.
2 SeekFreilich,kAaron;k Shanholt,k Henryk H.;k McCormack,kJosephk P.,k Planek Trigonometry,
k Silver,kBurdettkandkCompany,kNewkYork,kNY,k1934,korkanyksimilarkhigh-
schoolktrigonometryktextbook.
e is m ic i s o la ti o n
14 ClassicalkFORTRANk SolutionskManual
C
Thiskprogramkfindsktrianglekangl
eskC oppositek givenk sides.
C
C
promptkforkandkreadkthekside
klengthskPRINTk *,’sides:’
READk *,SA,SB,SC
C
C
useklawkofkcosinesktokfindkthe
kangleskCA=(SB2k+kSC2k-
kSA2)/(2.SBSC)kCB=(SA2k+kSC
2 k-
kSB2)/(2.SASC)kCC=(SA2k+kSB
2 k-kSC2)/(2.SASB)kA=ACOS(CA)
B=ACOS(CB)kC=ACOS(
CC)
C
C
convertkanglesktokdegreeskfor
koutputkPI=4.*ATAN(1.)
DPR=180./PIkA
=DPR*AkB=DP
RBkC=DPRC
PRINTk*,’oppositekangles:’kP
RINTk*,A,B,C
STOP
kEND
Somektypicalkinteractionskwithkthekprogramkarekshownkbelow.
unix[1]ka.outksid
es:
1 k 1 k 1
oppositekangles:
60.00000000k 60.00000000k 60.
unix[2]ka.outksid
es:
3 k 4 k 5
oppositekangles:
36.86989594k 53.13010025k 90.
unix[3]ka.outksid
es:
3 k 8 k 10
oppositekangles:
14.36151028k 41.40962219k 124.
unix[4]ka.outksid
es:
1 k 1 k 2
oppositekangles:
0.0000000000E+00k k 0.0000000000E+00k k 180.
unix[5]ka.outksid
es:
1 k 1 k 3
oppositek angles:k
NaNQk NaNQk NaNQ