Skip to content
Snippets Groups Projects
Commit d9c13854 authored by NESustatov's avatar NESustatov
Browse files

fibbonaci

parent 398a7b75
No related branches found
No related tags found
No related merge requests found
*.exe
.vscode
\ No newline at end of file
main.cpp 0 → 100644
#include<iostream>
/*
числа фиббоначи
мы хотим получить n-ый символ ряда фиббоначи
на выходе программы число n
должна вывессти число
*/
long unsigned fibbonaci(int n) {
if (n == 1 || n == 2) {
return 1;
}
long unsigned rezult_1 = 1;
long unsigned rezult_2 = 1;
for (int i = 3; i <= n; i++){
rezult_2 += rezult_1;
rezult_1 = rezult_2 - rezult_1;
}
// return fibbonaci(n-1) + fibbonaci(n-2);
return rezult_2;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cout << "Incorrect usage" << std::endl;
return 1;
}
int n = atoi(argv[1]);
if (n < 1) {
std::cout << "not" << std::endl;
return 2;
}
for (int i = 1; i <= n; i++){
std::cout << "Number " << i << ": " << fibbonaci(i) << std::endl;
}
std::cout << fibbonaci(n) << std::endl;
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment