Skip to content
Snippets Groups Projects
Commit 31774f07 authored by unknown's avatar unknown
Browse files

fibbonaci

parent ef1edae0
Branches main
No related tags found
No related merge requests found
*.exe
.vscode
\ No newline at end of file
a.exe 0 → 100644
File added
File added
main.cpp 0 → 100644
#include<iostream>
/*
Числа фибоначи
Мы хотим получить n-ный символ ряда Фиббоначи
На входе программы число n
Должна вывсети число.
*/
long long unsigned fibbonaci(int n) {
if (n == 1 || n == 2) {
return 1;
}
long long unsigned result_1 = 1;
long long unsigned result_2 = 1;
for (int i = 3; i <= n; i++) {
result_2 = result_1 + result_2;
result_1 = result_2 - result_1;
}
return result_2;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cout << "Incorrect usage" << std::endl;
return 1;
}
std::cout << argv[1] << std::endl;
int n = atoi(argv[1]);
if (n < 1) {
std::cout << "Use a nomber > 0" << std::endl;
return 2;
}
if (n > 93) {
std::cout << "Number too big!" << std::endl;
return 3;
}
for (int i = 1; i <= n; i++) {
std::cout << "Number " << i << ": " <<fibbonaci(i) << std::endl;
}
std::cout << fibbonaci(n) << std::endl;
std::cout << "Hello world" << 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