C 练习实例26

C 语言教程 · 2019-02-21 18:28:28

题目:利用递归方法求5!。

程序分析:递归公式:fn=fn_1*4!

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> int main() { int i; int fact(int); for(i=0;i<6;i++){ printf("%d!=%d\n",i,fact(i)); } } int fact(int j) { int sum; if(j==0){ sum=1; } else { sum=j*fact(j-1); } return sum; }

以上实例输出结果为:

0!=1
1!=1
2!=2
3!=6
4!=24
5!=120

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Algorithms

Algorithms

Sanjoy Dasgupta、Christos H. Papadimitriou、Umesh Vazirani / McGraw-Hill Education / 2006-10-16 / GBP 30.99

This text, extensively class-tested over a decade at UC Berkeley and UC San Diego, explains the fundamentals of algorithms in a story line that makes the material enjoyable and easy to digest. Emphasi......一起来看看 《Algorithms》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器