Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20231104-KursPodstawowyALX
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20231104-KursPodstawowyALX
Commits
98667cbf
Commit
98667cbf
authored
Dec 02, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fibonacci w pętli
parent
f27e98f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
Fib2.java
src/main/java/domowe/r2/z03_funkcje/Fib2.java
+33
-0
No files found.
src/main/java/domowe/r2/z03_funkcje/Fib2.java
0 → 100644
View file @
98667cbf
package
domowe
.
r2
.
z03_funkcje
;
import
java.util.Scanner
;
public
class
Fib2
{
static
long
fib
(
int
n
)
{
long
wynik
=
0
;
long
poprz
=
1
;
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
long
nowy
=
wynik
+
poprz
;
poprz
=
wynik
;
wynik
=
nowy
;
}
return
wynik
;
}
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
while
(
true
)
{
System
.
out
.
print
(
"Podaj argument: "
);
int
n
=
scanner
.
nextInt
();
if
(
n
<
0
)
break
;
long
p
=
System
.
nanoTime
();
var
wynik
=
fib
(
n
);
long
k
=
System
.
nanoTime
();
System
.
out
.
printf
(
"F(%d) = %d\n"
,
n
,
wynik
);
System
.
out
.
printf
(
" czas: %.6f s\n"
,
(
k
-
p
)*
1
e
-
9
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment