C#方法递归
来源:互联网 发布:linux cp 带目录结构 编辑:程序博客网 时间:2024/06/15 14:25
递归方法是一种可以调用自身的方法。以下是使用递归函数来计算给定数值的阶乘的示例:
using System;namespace CalculatorApplication{ class NumberManipulator { public int factorial(int num) { /* local variable declaration */ int result; if (num == 1) { return 1; } else { result = factorial(num - 1) * num; return result; } } static void Main(string[] args) { NumberManipulator n = new NumberManipulator(); //calling the factorial method Console.WriteLine("Factorial of 6 is : {0}", n.factorial(6)); Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7)); Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8)); Console.ReadLine(); } }}
结果为Factorial of 6 is: 720Factorial of 7 is: 5040Factorial of 8 is: 40320
阅读全文
0 0
- c#递归方法调用
- C#方法递归
- C#递归方法复制文件夹
- C# TreeView递归遍历方法
- C# TreeView递归遍历方法
- c#递归压缩文件夹方法
- C#递归方法遍历目录及子目录
- c# 查找文件夹的方法(递归)
- C#递归方法遍历目录及子目录
- C#递归
- c# 递归
- c#递归
- C#遍历目录树的方法(递归)
- 权限系统收获——C#递归方法实现zTree
- C# 用递归方法取多个数组的相同元素
- C#基础(9)——方法的重载、递归
- 递归方法
- 递归方法
- bzoj 3171: [Tjoi2013]循环格 费用流
- 【洛谷】2831 [Noip2016]愤怒的小鸟 状压DP
- mysql语句执行时间分析
- 【论文阅读】Shakti-T: A RISC-V Processor with Light Weight Security Extensions
- js获取url传递参数
- C#方法递归
- 括号匹配的检验
- 利用AD13设计PCB的问题总结21-30
- superset二次开发杂记
- HTML meta viewport属性说明
- Eclipse版本以及安装插件(以WindowBuilder为例)
- keil5.24.2 Jlink盗版检测停止工作问题解决
- NEUQACM OJ:1070 谭浩强C语言(第三版)习题9.1
- ssh(spring springMVC hibernate)的整合