求Fibonacci数(递归)

利用汇编语言计算斐波那契数列 基于汇编语言的计算斐波那契数程序设计题目要求程序接收由用户键入的范围在0~100(不包括0和100)之间的n值。根据给定的n值,计算Fibonacci数,其定义如下:FIB(1) = 1FIB(2) = 1FIB(n) = FIB(n-2) +FIB(n-1) (n>2)程序输出FIB(n)的值新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创 阅读详情

程序接收由用户键入的数N,根据给定的N值,计算Fibonacci数。

        Fibonacci数的定义如下:

             FIB(1)=1

             FIB(2)=1

             FIB(N)=FIB(N-2)+FIB(N-1)   N>=3   

 

data    segment
mess    db 'Input the N(<100):','$'
mess1   db 'F(','$'
mess2   db ')=','$'
num1    db 3
num2    db ?
num     dw ?
num3    db ?

result1 dw ?
result2 dw ?
f_end    dw 0
constant dw 10000,1000,100,10,1
flag    dw 0
data    ends
;**********************
code   segment
       assume cs:code,ds:data,es:data
start:
       mov ax,data
       mov ds,ax
       mov es,ax

       lea dx,mess
       mov ah,09h
       int 21h
      
       lea dx,num1
       mov ah,0ah
       int 21h
      
       mov dl,0ah   ;huiche
       mov ah,02h
       int 21h
       mov dl,0dh
       mov ah,02h
       int 21h

       xor cx,cx
       mov cx,num
       xchg cl,ch   ;因为从键盘输入的是字符串,保存时高位在低位的前面,所以                                    要交换,才能直接从内存中取出并正确
       mov num,cx
       call DTOH     ;将输入的十进制数转换成十六进制并保存
       mov bx,cx   
       xor dx,dx   ;DX放十进制数的百万位,即十六进制DX:AX
       call FINA
       push dx       ;后面会改变,所以要保护起来     

       lea dx,mess1
       mov ah,09h
       int 21h
      
       mov cx,num
       mov dl,ch
       mov ah,02h
       int 21h
       mov dl,cl
       mov ah,02h
       int 21h

       lea dx,mess2
       mov ah,09h
       int 21h

       mov bx,result2
       pop dx
     
       call HTOD     ;将保存的十六进制数转换成十进制并在屏幕上显示
    
       mov ah,4ch
       int 21h

;*************************
;10--->16
 DTOH PROC NEAR
       sub ch,30h
       sub cl,30h
       mov al,ch
       mov bl,10
       mul bl
       mov ch,0
       add cx,ax
       ret
DTOH   ENDP
      
;****************************
;***********************
;16--->10
HTOD PROC NEAR
      
       push bx
       mov flag,0
       mov cx,5
       lea si,constant
       mov bx,dx
dic_div:
      
       mov ax,bx
loop1:  mov dx,0
       div word ptr[si]      
       mov bx,dx
       mov dl,al

       cmp flag,0
       jnz print1
       cmp dl,0
       je  skip
       mov flag,1     
      
print1: add dl,30h
        mov ah,02h
        int 21h

skip:   add si,2
        loop dic_div
        cmp f_end,0
        jnz quit
        pop ax
        ;mov ax,bx
        mov cx,5
        lea si,constant
        mov flag,0
        mov f_end,1
        jmp loop1
       
quit:      RET
HTOD   ENDP
;****************8
FINA PROC NEAR
      
       cmp bx,1
       jz  L1
       cmp bx,2
       jz  L2
      
L_loop:
       dec bx
       call FINA
       mov ax,result2
      
       mov cx,result1
       add result2,cx
       adc dx,0
       mov result1,ax
      
      
       jmp exit

L1:    mov word ptr result1,1
       jmp exit
L2:
       mov result2,1
       dec bx
       call FINA
      
exit:  ret
FINA   ENDP
;*************************

code  ends
      end start

编程题: Fibonacci数列 题目描述Fibonacci数列是这样定义的:F[0] = 0F[1] = 1for each i ≥ 2: F[i] = F[i-1] + F[i-2]因此,Fibonacci数列就形如:0, 1, 1, 2, 3, 5, 8, 13, ...,在Fibonacci数列中的数我们称为Fibonacci数。给你一个N,你想让其变为一个Fibonacci数,每一步你可以把当前数字X变为X-1或者X+1... 阅读详情

相关推荐

汇编求Fibonacci数的源程序

求Fibonacci数程序设计 源程序。大家可以参考借鉴哦……

【转】斐波那契数列--递归算法学习

【问题】    编写计算斐波那契(Fibonacci)数列的第n项函数fib(n)。    斐波那契数列为:0、1、1、2、3、……,即:      fib(0)=0;      fib(1)=1;      fib(n)=fib(n-1)+fib(n-2)      (当n&gt;1时)。 写成递归函数有: int fib(int n) {    if (n==0)      return 0;...

cmjcmj8080的博客 814

斐波那契数(fibonacci汇编程序)

根据给定的n值,计算Fibonacci数 程序输出FIB(n)

java中用递归方法求第n个Fibonacci数

用递归方法求第n个Fibonacci数。源程序:import java.io.*;class Fibonacci{  public long Fibonacci(int n)               //用来计算n个Fibonacci的方法  {    if(n==1)      return 1;    else if(n==2)      retur

机器喵的休闲生活 2461

汇编 fibonacci序列

程序接收由用户键入的数N,根据给定的N值,计算Fibonacci数。 Fibonacci数的定义如下: FIB(1)=1 FIB(2)=1 FIB(N)=FIB(N-2)+FIB(N-1) N>=3

求Fibonacci数程序设计(汇编语言)

求Fibonacci数程序设计 目 录 一.课程设计任务书•••••••••••••••••••••••••••••••••••••••••••••••••••••2 二.正文••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••3 1.设计目的、设计内容、时间安排•••••••••••••••••••••••••••••••••••3 2.设计环境与与工具•••••••••••••••••••••••••••••••••••••••••••••••••3 3.程序设计算法说明、流程图••••••••••••••••••••••••••••••••••••••••3 4.源程序清单••••••••••••••••••••••••••••••••••••••••••••••••••••••••5 5.运行结果记录••••••••••••••••••••••••••••••••••••••••••••••••••••••8 6. 设计结果分析•••••••••••••••••••••••••••••••••••••••••••••••••••••••8 7.参考文献及其他••••••••••••••••••••••••••••••••••••••••••••••••••••8 三.评分表•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••9 四.封底••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••10

fibonacci斐波那契数列详解 递归求Fn非递归求Fn求n最近的斐波那契数

斐波那契fibonacci 斐波那契额数列即前两项F(0)和F(1)都是1,之后的每一项都是前两项相加和即F(3)=2,F(4)=3,F(5)=5; 通项公式:F(n+2)=F(n+1)+F(n)。 1.递归求fn 给出一个n 求斐波那契数列的Fn 递归解法即写一个递归函数,注意两个点 1: 递归边界条件(n=0或者n=1) 2:递归式 F(n+2)=F(n+1)+F(n) 代码: #include<cstdio> int F(int n) { if(n==0||n==1) return 1;

蔡尼玛的博客 2341

Dify工作流自动化:如何用Trae AI助手10倍提升你的开发效率(含避坑指南)

本文详细介绍了如何利用Trae AI助手自动化生成Dify工作流,实现开发效率的10倍提升。通过构建DSL示例库、精准需求描述和四步实战法,开发者可将重复的配置工作交给AI,快速生成可运行的工作流,并提供了关键的避坑指南。

weixin_29062865的博客 372

java用递归求fibonacci,在Java中使用线程和递归来计算Fibonacci数

I'm relatively new in the Java world and I have a problem which I don't understand.I have a Class (to get the fibonacci row):class Fib {public static int f(int x){if ( x < 2 )return 1;elsereturn f(...

weixin_36416921的博客 149

【第三只眼:Oracle通过归档日志查看系统的业务高峰sql】

根据oracle归档的业务高峰量,查找业务sql,进行优化

霍然的专栏 580

ESP32-S3驱动PCA9685模块:I2C扩展16路舵机控制实战指南

本文提供了ESP32-S3通过I2C总线驱动PCA9685模块扩展16路PWM输出的完整实战指南。详细解析了PCA9685模块原理、硬件连接、I2C地址配置,并给出了核心驱动代码与角度控制函数,帮助开发者解决微控制器PWM引脚不足的问题,轻松实现多路舵机控制。

weixin_32005771的博客 525

用C语言递归和非递归实现Fibonacci斐波那契数列求第n个斐波那契数

#include <stdio.h> #include <stdlib.h> //斐波那契数 //递归 int Fibonacci(int n) { if(n1||n2) { return 1; } else return Fibonacci(n-1)+Fibonacci(n-2); } //非递归 int Fibonacci1(int n) { int f1=1; int...

lzh_99999的博客 1893

CondaHTTPError: HTTP 404 NOT FOUND for url

用conda创建新环境时出现问题了。

qq_40713201的博客 1270

已知Fibonaccci数列为1,1,2,3,5,8,13...,使用递归法写一个求Fibonaccci数的函数,在main()函数输入一个自然数,输出不小于该自然数的最小的一个Fibonacci数

【代码】已知Fibonaccci数列为1,1,2,3,5,8,13...,使用递归法写一个求Fibonaccci数的函数,在main()函数输入一个自然数,输出不小于该自然数的最小的一个Fibonacci数。

2302_80472547的博客 1436

基于STM32L4XX、HAL库的ESP32-S3-WROOM-1-N4 WIFI模块驱动程序设计

/ 检查是否收到完整的一行(以\r\n结尾)// 例如: 解析AT命令响应或MQTT消息等。// UART2初始化已在CubeMX中配置。// USART2初始化函数(由CubeMX生成)// 缓冲区溢出,重置。// 如果需要等待响应。// 处理接收到的数据。// 处理接收到的数据。// 等待ESP32模块启动。// 主循环其他任务。// 启用UART全局中断。// 发送HTTP GET请求。// 发送AT测试命令。// 连接Wi-Fi。// UART中断回调函数。

zhusl6688的博客 289

图解B+树的插入过程

B+ 树在现代数据库中很常见,如果我们了解它,在工作中可能对性能优化会有更好的帮助! 最近我一直在思考 B+ 树的高度是由什么决定的。知道我了解了 B+ 树的插入过程,才有一种恍然大悟的感觉! 网上的一些资料杂乱无章,不同的数据库可能还有对 B+ 树有不同的实现。但是万变不离其宗,B+ 树的定义,大致如下所示: 总结一下,B+ 树有下面 5 个重要的特点。 B+ 树包含 2 种类型的结点: 内部结点(也称索引结点)和叶子结点。 根结点本身即可以是内部结点,也可以是叶子结点。 根结点的关键字个数最

愿君出走半生,归来时仍是少年 2135

Fibonacci数列

无穷数列1,1,2,3,5,8,13,21,34,55,……,称为Fibonacci数列。它可以递归地定义为: 第n个Fibonacci数可递归地计算如下: int fibonacci(int n) { if (n <= 1) return 1; return fibonacci(n-1)+fibonacci(n-2); } 编写完整的主函数,分别记录利用上述递归函数求第47, 48, 49, 50, 51,52个Fibonacci数所花费的时间。 package work; public clas

yidaa2的博客 1118

【Matlab】matlab代码实现迭代学习控制

该文介绍了在Matlab中实现迭代学习控制(ILC)的方法。ILC通过利用历史轨迹数据来优化重复任务的控制性能。文章提供了一个步进电机控制示例,包括:1)定义正弦轨迹;2)设置100次迭代和0.1学习率;3)建立二阶系统模型;4)执行ILC算法计算控制输入;5)绘制期望轨迹与实际输出的对比图。该示例展示了ILC的基本实现过程,并指出实际应用可能需要更复杂的设计。代码演示了误差计算、控制输入更新和结果可视化等关键步骤。

unber的博客 202

Java_ 求任意位斐波那契数(Fibonacci:1,1,2,3,5,8,13...)//循环|递归

方法1 循环迭代 import java.util.Scanner; /* * 求任意一位斐波那契数,循环迭代方法 *@author Chill_Lyn * * */ public class Fibonacci1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in...

Chill Lyn 887

【TC3xx芯片】TC3xx芯片PFlash的ECC校验问题补充

TC3xx芯片PFlash的ECC校验问题补充

qq_36056498的博客 1154

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PTA 使用函数输出指定范围内的Fibonacci数---->>>使用递归完成斐波那契数

其中函数fib须返回第n项Fibonacci数;函数PrintFN要在一行中输出给定范围[mn]内的所有Fibonacci数,相邻数字间有一个空格,行末不得有多余空格。如果给定区间内没有Fibonacci数,则输出一行“No Fibonacci number”。

x3477144355的博客 661

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

基础算法——十进制转二进制、算术累加、递归求斐波那契数(Fibonacci number)

尚学堂——Java基础——第三章习题 package GUI_8; import java.security.DigestException; import java.util.Scanner; /**百战程序员-第三章习题答案 * 题目网址:https://www.sxt.cn/Java_jQuery_in_action/openketang-Exercise.html * 一、选择题 * 1.A 2.BD 3.A 4.BB 5.B * 二、简单题 * 1.相同点: 都是选择结构

Etui۹(・༥・´)و的博客 585

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

用c语言实现非递归求第n个斐波那契数(Fibonacci)。(不考虑溢出)

求第n个斐波那契数。(不考虑溢出) int fib(int n) { int result; int pre_result; int next_older_result; result = pre_result = 1; while (n > 2) { n -= 1; next_older_result = pre_result; pre_result = result; result = ...

lzh_99999的博客 341

【PTA】求算式前n项的和--递归法C语言

求1+1/2+2/3+3/5+5/8+8/13+13/21……的前n项的和。要求:用递归完成。

2301_80465376的博客 887

【C语言】斐波那契数列

数的函数,在主函数中输入一个自然数,输出不小于该自然数的最小的一个。

wwweerie的博客 603
dong310
博客等级 码龄17年 4粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值