C#:用 BigInteger 计算 斐波那契数列

embedded/2024/9/22 11:05:40/

using System.Numerics; 

计算 斐波那契数列(Fibonacci sequence),不受长整型位数限制。

编写  fibonacci.cs  如下

// C# program for Fibonacci Series
// using Dynamic Programming
using System;
using System.Numerics;class fibonacci {static BigInteger fib(int n){	BigInteger a = new BigInteger(0);BigInteger b = new BigInteger(1);BigInteger c = new BigInteger(0);int i;for (i = 2; i <= n; i++) {c = a + b;a = b;b = c;}return b;}// Fibonacci Series testpublic static void Main(string[] args){if (args.Length <1){Console.WriteLine(" usage: fib.exe n ");return;}       int n;if (int.TryParse(args[0], out n)){if (n >1) Console.WriteLine(fib(n));} else {Console.WriteLine(" input n must be +int ");}}
}

where csc
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe

编译  csc fibonacci.cs
fibonacci.cs(8,9): error CS0246: 未能找到类型或命名空间名称“BigInteger


编译  csc  /r:System.Numerics.dll  fibonacci.cs

运行 fibonacci.exe 1000
参阅:https://www.geeksforgeeks.org/program-for-nth-fibonacci-number/


http://www.ppmy.cn/embedded/11785.html

相关文章

Linux:SSL中加密的数字证书主要内容

数字证书中的内容 # 注意&#xff1a;下列证书信息项目&#xff0c;在面试时常问 Country Name (2 letter code) [AU]:86 # 国家代码 State or Province Name (full name) [Some-State]:shanxi # 省份 Locality Name (eg, city) []:xian # 城市 Organiza…

Abaqus2024 安装教程(附免费安装包资源)

鼠标右击软件压缩包&#xff0c;选择“解压到Abaqus2024”。 鼠标右击“此电脑”&#xff0c;选择“属性”。 点击“高级系统设置”。 点击“环境变量”。 点击“新建”。 变量名输入&#xff1a;NOLICENSECHECK 变量值输入&#xff1a;true 然后点击“确定”。 点击“确定”。…

【linux】进程地址被占用

在强制关闭一个udp程序后&#xff0c;重启该程序报错&#xff1a; bind error: Address already in use 查找并关闭占用端口的进程&#xff1a; 首先&#xff0c;确定哪个进程占用了目标端口。在Linux系统中&#xff0c;可以使用以下命令&#xff1a; netstat -tulnp | grep …

MySQL 试图

视图功能在 5.0 以后的版本启用 视图是一张虚表。数据表确实包含了具体数据并且保存到硬盘中的实表。视图使用数据检索语句动态生 成的一张虚表。每一次数据服务重启或者系统重启之后&#xff0c;在数据库服务启动期间&#xff0c;会使用创建视图的语 句重新生成视图中的数据&…

【SpringBoot实战篇】获取用户详细信息

1 明确需求 1需要获取用户详细信息 2 接口文档 1基本信息 2请求参数 无 3 响应数据 响应数据类型&#xff1a;application/json 响应参数说明&#xff1a; 响应数据样例 3 思路分析 1用户名在请求头里获取 4 开发 4.1 控制器usercontroller GetMapping("/userInfo")p…

[Meachines][Easy]Bizness

Main $ nmap -p- 10.10.11.252 --min-rate 1000 $ dirsearch -u https://bizness.htb/ $ whatweb https://bizness.htb/control/login 存在一个未授权的RCE $ git clone https://github.com/jakabakos/Apache-OFBiz-Authentication-Bypass.git $ cd Apache-OFBiz-Authenticat…

统一SQL 支持Oracle number/decimal/dec/numeric转换

统一SQL介绍 https://www.light-pg.com/docs/LTSQL/current/index.html 源和目标 源数据库&#xff1a;Oracle 目标数据库&#xff1a;Postgresql&#xff0c;TDSQL-MySQL&#xff0c;达梦8&#xff0c;LightDB-Oracle 操作目标 通过统一SQL&#xff0c;将Oracle中的numb…

JRebel热部署SpringBoot+MyBatis-Plus实现不重启更新修改后MyBatis的XML文件

安装JRebel热部署插件 《JRebel插件安装教程》 《JRebel mybatisPlus extension下载Zip离线安装》 在线安装JRebel mybatisPlus extension 插件商店直接搜JRebel mybatisPlus extension pom.xml 引入依赖 <dependency><groupId>com.baomidou</groupId>…