-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第4章の練習問題「Fibonatti Number」を修正 #29
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
24bed1e
フィボナッチ数列の初項を1とすることを明記
YuHima03 f92f69c
Fibonatti Numberの解答のコードを修正
YuHima03 c76f9cd
整数N→正の整数N に表記を変更
YuHima03 82b0f79
fibonatti.md のmdを修正
YuHima03 0ae7d21
Merge branch 'main' into chapter-4_fibonatti
Takeno-hito 4616086
解答のfor文の書き方を修正
YuHima03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,8 @@ | ||||||||
# 4-xx. Fibonatti Number | ||||||||
|
||||||||
整数$N$を受け取り、フィボナッチ数列の$N$番目を出力しよう。 | ||||||||
正の整数$N$を受け取り、フィボナッチ数列の$N$番目を出力しよう。 | ||||||||
|
||||||||
ただし、フィボナッチ数列は $\{1,1,2,...\}$ とします。 | ||||||||
|
||||||||
:::spoiler Hint 1 | ||||||||
$F_{n}=F_{n-1}+F_{n-2}$をfor文で計算しよう。 | ||||||||
|
@@ -24,7 +26,7 @@ int main() { | |||||||
int n; | ||||||||
cin >> n; | ||||||||
int second_latest = 0, latest = 1; | ||||||||
for (int i = 2; i < n; i++) { | ||||||||
for (int i = 1; i < n; i++) { | ||||||||
int next = second_latest + latest; | ||||||||
second_latest = latest; | ||||||||
latest = next; | ||||||||
|
@@ -44,11 +46,11 @@ int main() { | |||||||
int n; | ||||||||
cin >> n; | ||||||||
vector<int> fibonatti_sequence = {0, 1}; | ||||||||
for (int i = 2; i < n; i++) { | ||||||||
for (int i = 1; i < n; i++) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同様 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 上と同様です.
Suggested change
|
||||||||
int next = fibonatti_sequence[i-1] + fibonatti_sequence[i-2]; | ||||||||
fibonatti_sequence.push_back(next); | ||||||||
} | ||||||||
cout << fibonatti_sequence.back() << endl; | ||||||||
} | ||||||||
|
||||||||
``` | ||||||||
::: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
回数のためにしか使ってないなら
としたいです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返信遅くなりすみません.
i番目を計算するほうが分かりやすいと思うので, その旨のコメントを追加して以下でどうでしょうか.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
良さげ!コミットしちゃってください