zoukankan
html css js c++ java
求阶乘的函数
long fac(int k)
{
long f=1;
for (int i=1;i<=k;i++)
f=f*i;
return f;
}
#include
<
stdio.h
>
#include
<
conio.h
>
long
fac(
int
);
void
main()
{
int
k;
long
result;
clrscr();
scanf(
"
%d
"
,
&
k);
result
=
fac(k);
printf(
"
%ld
"
,result);
}
long
fac(
int
k)
{
long
f
=
1
;
for
(
int
i
=
1
;i
<=
k;i
++
)
f
=
f
*
i;
return
f;
}
**********************************************************************************************
用递归求n!
#include
<
stdio.h
>
#include
<
conio.h
>
long
fac(
int
);
void
main()
{
long
y;
int
n;
clrscr();
scanf(
"
%d
"
,
&
n);
y
=
fac(n);
printf(
"
%d!=%ld
"
,n,y);
}
long
fac(
int
n)
{
long
f;
if
(n
==
0
)
f
=
1
;
else
f
=
n
*
fac(n
-
1
);
/**/
/*
递归调用,求(n-1)!
*/
return
f;
}
查看全文
相关阅读:
UITableview cell 的多选
抽屉开关控制器
NSDate 获取明天、后天的日期
UITextField里面的 placeholder颜色和字体
判断返回数据是否为 null
UIButton 长按点击 背景改变效果
UIButton 去除按下效果(阴影)
iOS-RunLoop,为手机省电,节省CPU资源,程序离不开的机制
iOS-真机调试
iOS-设置启动图片
原文地址:https://www.cnblogs.com/qixin622/p/619422.html
最新文章
剑指 Offer 57. 和为s的两个数字 哈希 双指针 二分查找
程序员面试金典 <Cracking the Coding Interview> 面试题 04.01. 节点间通路
Leetcode 2. 两数相加 && 面试题 02.05. 链表求和
程序员面试金典 <Cracking the Coding Interview> 面试题 02.08. 环路检测
程序员面试金典 <Cracking the Coding Interview> 面试题 01.05. 一次编辑
程序员面试金典 <Cracking the Coding Interview> 面试题 02.06. 回文链表 双指针 数组
程序员面试金典 <Cracking the Coding Interview> 面试题 02.03. 删除中间节点
[LeetCode] Path Sum II
[LeetCode] Min Stack
[LeetCode] Path Sum
热门文章
[LeetCode] Pascal's Triangle II
[LeetCode] Pascal's Triangle
[LeetCode] Remove Duplicates from Sorted List
[LeetCode] Merge Sorted Array
[LeetCode] Flatten Binary Tree to Linked List
[LeetCode] Valid Palindrome
[LeetCode] Binary Tree Preorder Traversal
TCP移动端跟服务器数据交互
UITableview cell中多个按钮
UITableview 多行删除
Copyright © 2011-2022 走看看