Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG-material-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yue Wu
PROG-material-public
Commits
958490be
Commit
958490be
authored
1 year ago
by
dali662d
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d6d88d98
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sonderuebung/WiSe23-24/SU04_2023_11_15/03_taschenrechner_mit_funktionen.f95
+119
-0
119 additions, 0 deletions
...3-24/SU04_2023_11_15/03_taschenrechner_mit_funktionen.f95
with
119 additions
and
0 deletions
Sonderuebung/WiSe23-24/SU04_2023_11_15/03_taschenrechner_mit_funktionen.f95
0 → 100644
+
119
−
0
View file @
958490be
program
taschenrechner
implicit
none
CHARACTER
::
op
! Operator
CHARACTER
::
end
DO
WRITE
(
*
,
*
)
"Gebe einen Rechenoperator (+,-,*,/) ein!"
WRITE
(
*
,
*
)
"Fuer die Berechnung einer Kreisflaeche schreibe A"
WRITE
(
*
,
*
)
"Fuer Quader Ober- und Unterflaeche Q"
DO
! Eingabe wird wiederholt, wenn der Operaor ungültig ist
READ
(
*
,
*
)
op
IF
(
op
==
"+"
.OR.
op
==
"-"
.OR.
op
==
"*"
.OR.
op
==
"/"
.OR.
op
==
"A"
.OR.
op
==
"Q"
)
EXIT
WRITE
(
*
,
*
)
"Die Eingabe ist ungueltig. Gebe einen neuen Operator ein."
END
DO
IF
(
op
==
"+"
.OR.
op
==
"-"
.OR.
op
==
"*"
.OR.
op
==
"/"
)
THEN
CALL
calc
(
op
)
ELSEIF
(
op
==
"A"
)
THEN
CALL
circle
ELSEIF
(
op
==
"Q"
)
THEN
CALL
quader
ELSE
WRITE
(
*
,
*
)
"Operatorfehler"
END
IF
! Austrittsbedingung
WRITE
(
*
,
*
)
"Soll eine weitere Rechnung statt finden? (j/n)"
READ
(
*
,
*
)
end
IF
(
end
==
"n"
)
EXIT
END
DO
CONTAINS
!!! Rechnungen des alten Taschenrechners
subroutine
calc
(
op
)
character
::
op
integer
::
a
,
b
integer
::
res
WRITE
(
*
,
*
)
"Gebe zwei Zahlen ein!"
READ
(
*
,
*
)
a
,
b
SELECT
CASE
(
op
)
CASE
(
"+"
)
res
=
a
+
b
CASE
(
"-"
)
res
=
a
-
b
CASE
(
"*"
)
res
=
a
*
b
CASE
(
"/"
)
res
=
division
(
a
,
b
)
CASE
DEFAULT
WRITE
(
*
,
*
)
"Der Eingegebene Operator ist ungueltig."
END
SELECT
WRITE
(
*
,
*
)
"Das Ergebnis ist "
,
res
end
subroutine
calc
function
division
(
a
,
b
)
result
(
res
)
integer
::
a
,
b
integer
::
res
DO
! Hiermit wird Division durch 0 ausgeschlossen, ohne die Rechnung abzubrechen
IF
(
b
==
0
)
THEN
WRITE
(
*
,
*
)
"Division durch 0 ist veboten! Gebe die zweite Zahl erneut ein."
READ
(
*
,
*
)
b
END
IF
END
DO
res
=
a
/
b
end
function
division
!!! Neue Rechnungen
subroutine
quader
INTEGER
::
a
,
b
,
c
,
res
WRITE
(
*
,
*
)
"Gebe die Laenge, Hoehe und Breite eines Quaders an."
READ
(
*
,
*
)
a
,
b
,
c
! Oberfläche
res
=
2
*
a
*
b
+
2
*
b
*
c
+
2
*
c
*
a
WRITE
(
*
,
*
)
"Die Oberfaeche ist "
,
res
! Volumen
res
=
a
*
b
*
c
WRITE
(
*
,
*
)
"Das Volumen ist "
,
res
end
subroutine
quader
subroutine
circle
REAL
::
r
,
res
REAL
,
PARAMETER
::
pi
=
3.141592
WRITE
(
*
,
*
)
"Welchen Radius hat der Kreis?"
READ
(
*
,
*
)
r
! Kreisumfang
res
=
pi
*
r
*
2
WRITE
(
*
,
*
)
"Der Umfang des Kreises ist "
,
res
! Kreisvolumen
res
=
pi
*
r
**
2
WRITE
(
*
,
*
)
"Das Volumen des Kreises ist "
,
res
end
subroutine
circle
end
program
taschenrechner
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment