当前位置:网站首页>c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
2022-06-26 09:34:00 【坦桑尼亚奥杜威峡谷能人】
long jiecheng(int num){
long result=1,i;
for(i=1;i<=num;i++){
result*=i;
}
return result;
}
long pingfang(int a){
return jiecheng(a*a);
}
int main(int argc, char *argv[]) {
// s=2 2! + 3 3! + 4 4!
int i;
long res=0;
for(i=2;i<=4;i++){
res+=pingfang(i);
}
printf("%1d",res);
return 0;
}
//*********************************************************
// 4的递归阶乘 4!= 1*2*3*4 = 4*3*2*1
long jiecheng(int n){
long result;
if(n<=1){
result=1;
}else{
result=n*jiecheng(n-1); //
}
return result;
}
int main(int argc, char *argv[]) {
printf("%d",jiecheng(4));
return 0;
}
//*********************************************************
// 斐波那契前12和 1 1 2 3 5 8 13 21 34
int f(int n){
if(n==1 || n==2){
return 1;
}else{
return f(n-1)+f(n-2); //
}
}
int main(int argc, char *argv[]) {
int sum=0,i;
for(i=1;i<=12;i++){
sum += f(i);
}
printf("%d",sum);
return 0;
}
边栏推荐
- MapReduce&Yarn理论
- LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
- Differences between VI and vim and common commands
- Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
- Flink入门——单词统计
- kubernetes集群部署(v1.23.5)
- 2021-11-12 vrep vision sensor configuration
- Origin of QPM
- Summary of common commands of vim
- 【CVPR 2021】Unsupervised Pre-training for Person Re-identification(UPT)
猜你喜欢

2021-11-22 运动规划杂记
![[pulsar learning] pulsar Architecture Principle](/img/ec/5ab9aabc2beafd4238dc8055ba6fb2.png)
[pulsar learning] pulsar Architecture Principle

Creation and use of XSync synchronization script (taking debian10 cluster as an example)

c语言语法基础之——指针(字符、一维数组) 学习

Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014

The shutter tabbar listener is called twice

Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)

online trajectory generation
QPM performance monitoring components - General
![[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network](/img/a9/1361df052f0474e5c50b948a92c42a.jpg)
[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network
随机推荐
Solve Django's if Version (1, 3, 3): raise improverlyconfigured ('mysqlclient 1.3.3 or new is required
Jz2440--- using uboot burning program
【CVPR 2021】Intra-Inter Camera Similarity for Unsupervised Person Re-Identification (IICS++)
[open5gs] open5gs installation configuration
"One week's data collection" - logic gate
The 100000 line transaction lock has opened your eyes.
How to solve the sample imbalance problem in machine learning?
Teach you to use shell script to check whether the server program is running
集合对象复制
Optimization of power assisted performance of QPM suspended window
The shutter tabbar listener is called twice
2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
SQL function
install ompl. sh
Curriculum learning (CL)
MapReduce & yarn theory
Spark based distributed parallel processing optimization strategy - Merrill Lynch data
Single sign on logic
LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
SQL 函数