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
8bd73c76
Commit
8bd73c76
authored
1 year ago
by
Jonas Riedel
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
7d8d1bc1
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
Uebung/WiSe23-24/functions.f95
+62
-0
62 additions, 0 deletions
Uebung/WiSe23-24/functions.f95
with
62 additions
and
0 deletions
Uebung/WiSe23-24/functions.f95
0 → 100644
+
62
−
0
View file @
8bd73c76
module
function_introduction_module
implicit
none
private
!Modulinformationen privat
public
::
f
,
ggT
!Export der Funktionen
contains
function
f
(
x
)
!Funktionsname und formale Argumente
integer
,
intent
(
in
)
::
x
!Funktionsparameterdeklarierung (Typen), intent()-Attribute
integer
::
f
!Funktionswertdeklaierung, kein intent()-Attribut
real
::
grenze
!lokale Variablendeklaration, Zugriff nur innerhalb der Funktion
grenze
=
1.5
if
(
x
>
grenze
)
then
f
=
x
*
x
else
f
=
x
end
if
end
function
f
recursive
function
ggT
(
a
,
b
)
result
(
gcd
)
integer
,
intent
(
in
)
::
a
,
b
integer
::
gcd
if
(
b
==
0
)
then
!Basisfall
gcd
=
a
else
gcd
=
ggT
(
b
,
modulo
(
a
,
b
))
!rekursiver Fall
end
if
end
function
! Schreibe eine Funktion welche eine Zahl n als Parameter nutzt um die Summe der ersten n natürlichen Zahlen zu berechnen.
! Schreibe eine rekursive Funktion, welche eine Zahl n als Parameter nutzt um die Summe der ersten n natürlichen Zahlen zu berechnen.
! Schreibe eine Funktion welche eine Zahl n als Parameter nutzt und überprüft, ob diese eine perfekte Zahl ist. (n == Summe echter Teiler)
end
module
function_introduction_module
program
function_introduction
use
function_introduction_module
implicit
none
integer
::
x
x
=
2
write
(
*
,
*
)
"This is the result of a function f applied on x (in this case 2):"
write
(
*
,
*
)
f
(
x
)
!Funktionsaufruf
write
(
*
,
*
)
"This is the result of a function ggT applied on 5 and 10:"
write
(
*
,
*
)
ggT
(
10
,
12
)
!Funktionsaufruf
end
program
function_introduction
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