当前位置:网站首页>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;
}
边栏推荐
- The most complete and simple nanny tutorial: deep learning environment configuration anaconda+pychart+cuda+cudnn+tensorflow+pytorch
- Js--- get the data with the same key value in the object array to get a new array
- 【AAAI 2021】Few-Shot One-Class Classification via Meta-Learning 【FSOCC via Meta-learning】
- Jz2440--- using uboot burning program
- LeetCode 958. Completeness checking of binary tree
- Install new version cmake & swig & tinyspline
- thinkphp6.0的第三方扩展包,支持上传阿里云,七牛云
- 2021-11-22 运动规划杂记
- 教你用shell脚本检测服务器程序是否在运行
- 进入页面输入框自动获取焦点
猜你喜欢

2021-11-29 quintic polynomial of trajectory planning

logback

【CVPR 2021】Unsupervised Multi-Source Domain Adaptation for Person Re-Identification (UMSDA)

全面解读!Golang中泛型的使用

How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card

計算領域高質量科技期刊分級目錄

Badge series 7: use of codacy

十万行事务锁,开了眼界了。

Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)

c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
随机推荐
MapReduce&Yarn理论
测试须知——常见接口协议解析
【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort
The first techo day Tencent technology open day, 628
online trajectory generation
进入页面输入框自动获取焦点
Speed test of adding, deleting, modifying and querying 5million pieces of data in a single MySQL table
Badge collection 6:api\_ Use of level
online trajectory generation
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(2)详解
SQL 函数
Notes on sports planning on November 22, 2021
How to correctly open the USB debugging and complete log functions of Huawei mobile phones?
【Open5GS】Open5GS安装配置
Joint Noise-Tolerant Learning and Meta Camera Shift Adaptation for Unsupervised Person Re-ID
How does flutter transfer parameters to the next page when switching pages?
QPM suspended window setting information
Badge series 8: generate a personalized Badge
LeetCode 958. 二叉树的完全性校验
How to solve the sample imbalance problem in machine learning?