Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
2
2024 Code Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Programming 2
2024 Code Examples
Commits
1b2b55d6
Commit
1b2b55d6
authored
10 months ago
by
Andreas Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
+= fib_tail_rec
parent
e45921ee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Lectures/09/Makefile
+13
-5
13 additions, 5 deletions
Lectures/09/Makefile
Lectures/09/fib_tail_rec.c
+36
-0
36 additions, 0 deletions
Lectures/09/fib_tail_rec.c
with
49 additions
and
5 deletions
Lectures/09/Makefile
+
13
−
5
View file @
1b2b55d6
OPT
=
"-O3"
fib
:
fib.c test_fib.c
cc
-o
test_fib.o
-c
test_fib.c
cc
-o
fib.o
-c
fib.c
cc
$(
OPT
)
-o
fib.o
-c
fib.c
cc test_fib.o fib.o
-o
fib
fib_rec
:
fib_rec.c test_fib.c
cc
-DNDEBUG
-o
test_fib.o
-c
test_fib.c
cc
-o
fib_rec.o
-c
fib_rec.c
cc
$(
OPT
)
-o
fib_rec.o
-c
fib_rec.c
cc test_fib.o fib_rec.o
-o
fib_rec
fib_tail_rec
:
fib_tail_rec.c test_fib.c
cc
-DNDEBUG
-o
test_fib.o
-c
test_fib.c
cc
$(
OPT
)
-o
fib_tail_rec.o
-c
fib_tail_rec.c
cc test_fib.o fib_tail_rec.o
-o
fib_tail_rec
fib_dp
:
fib_dp.c test_fib.c
cc
-DNDEBUG
-o
test_fib.o
-c
test_fib.c
cc
-o
fib.o
-c
fib_dp.c
cc
$(
OPT
)
-o
fib.o
-c
fib_dp.c
cc test_fib.o fib.o
-o
fib_dp
fib_lv
:
fib_lv.c test_fib.c
cc
-DNDEBUG
-o
test_fib.o
-c
test_fib.c
cc
-o
fib.o
-c
fib_lv.c
cc
$(
OPT
)
-o
fib.o
-c
fib_lv.c
cc test_fib.o fib.o
-o
fib_lv
all
:
fib fib_rec fib_dp fib_lv
all
:
fib fib_rec
fib_tail_rec
fib_dp fib_lv
clean
:
rm
*
.o
rm
fib
rm
fib_rec
rm
fib_tail_rec
rm
fib_dp
rm
fib_lv
This diff is collapsed.
Click to expand it.
Lectures/09/fib_tail_rec.c
0 → 100644
+
36
−
0
View file @
1b2b55d6
#include
<stdio.h>
#include
<stdlib.h>
#include
"test_fib.h"
unsigned
int
fib_rec
(
unsigned
int
i
,
unsigned
int
a
,
unsigned
int
b
)
{
if
(
i
==
0
)
{
return
a
;
}
else
{
return
fib_rec
(
i
-
1
,
b
,
a
+
b
);
}
}
unsigned
int
fib
(
unsigned
int
n
)
{
return
fib_rec
(
n
,
0
,
1
);
}
int
main
(
int
argc
,
char
**
argv
)
{
test_fib
();
if
(
argc
!=
2
)
{
printf
(
"Usage: fib <number>
\n
"
);
return
1
;
}
unsigned
int
n
=
atoi
(
argv
[
1
]);
unsigned
int
f
=
fib
(
n
);
printf
(
"fib(%d) = %d
\n
"
,
n
,
f
);
}
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