From 7b07eb048fd3c7c020f389e87ac5fb940a70ffe1 Mon Sep 17 00:00:00 2001 From: flykhan Date: Sat, 24 Jun 2023 10:38:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=90=E6=B3=A2=E9=82=A3=E5=A5=91=E6=95=B0?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day7/homework/oh3.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 day7/homework/oh3.cpp diff --git a/day7/homework/oh3.cpp b/day7/homework/oh3.cpp new file mode 100644 index 0000000..8072471 --- /dev/null +++ b/day7/homework/oh3.cpp @@ -0,0 +1,27 @@ +// 输入一个整数,输出它的斐波那契数列。 +// 例如:输入10,输出1 1 2 3 5 8 +#include + +using namespace std; + +int main() +{ + int n; + cout << "请输入一个整数:"; + cin >> n; + + int a = 1; + int b = 1; + int c = 0; + cout << a << "\t" << b << "\t"; + while (c <= n) + { + c = a + b; + if (c <= n) + cout << c << "\t"; + a = b; + b = c; + } + + return 0; +} \ No newline at end of file