当前位置:网站首页>非递归打印斐波那契数列
非递归打印斐波那契数列
2022-06-22 05:04:00 【姜学迁】
#include <stdio.h>
int main()
{
int n; //要打印的数列元素个数
int a = 1, b = 1; //数列第一项和第二项的初始值
int c = 0; //数列元素值
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
if (i == 1 || i == 2)
{
printf("%-3d\t", 1);
}
else
{
c = a + b; //第三项等于前两项之和
printf("%-3d\t", c); //输出第三项
a = b; //原第二项变成新第一项
b = c; //原第三项变成新第二项
}
}
return 0;
}流程图:
边栏推荐
- mysql day02课堂笔记
- MySQL day01 class notes
- php正则怎么去掉括号内容
- lua笔记
- MySQL day02 class notes
- Web page design and production final assignment report - College Students' online flower shop
- IDP depth | what kind of data analysis and mining tools do enterprises need?
- Graph calculation on nlive:nepal's graph calculation practice
- [camp] at the beginning, improve [leopard] power - vivo activity plug-in management platform
- Flink deployment mode (I) - standalone and Application
猜你喜欢

【故障诊断】CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace b

The feeling of leaving full-time for a single month!

9 practical shell scripts, recommended collection!

Progress information collection for progress control of Zhiyuan project management SPM system

基于深度学习的目标检测算法面试必备(RCNN~YOLOv5)

Accelerate the promotion of industrial Internet, and map out a new blueprint for development

laravel的服务容器,服务提供者,门面的理解

In 2022, the super intern plans to make a breakthrough in the offer of it famous enterprises, and the nine high salary skills help the dream of famous enterprises
![[chrome] Google tips Google browser comes with scrolling screenshot (full screen shot)](/img/9b/6ad704959a77abf9cb28fdd33b81b5.png)
[chrome] Google tips Google browser comes with scrolling screenshot (full screen shot)

10道不得不会的 Redis 面试题
随机推荐
重构思维系列2-函数及变量
restframework读取和非读取序列处理
Cloud native enthusiast weekly: Chaos mesh upgraded to CNCF incubation project
This is a picture
The Impossible Triangle of NLP?
go学习(一、基础语法)
【科研笔记】Focal Loss
【使用指南】使用公共的conda创建环境
Go learning (II. Built in container)
A domestic developer opened the "programmer's Guide to cooking" and became popular!
[user guide] create an environment using public CONDA
【故障诊断】CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace b
VirtualBox 6.1.34 发布
10 "no no no" redis interview questions
[sdx62] IPA log fetching instructions
使用Chrome调试微信内置浏览器
招贤纳士-第23期
Arrangement of soft test subjects in the second half of 2022
Zset type of redis
【故障诊断】cv2.imwrite无法写入图片,但程序就是不报错