当前位置:网站首页>c语言语法基础之——函数 小程序 求阶乘
c语言语法基础之——函数 小程序 求阶乘
2022-06-26 09:34:00 【坦桑尼亚奥杜威峡谷能人】
// 圆的面积 差
double area(int r)
{
return 3.14*r*r;
}
int main(int argc, char *argv[]) {
int r1=4,r2=2,r3=1;
double redarea=area(r1)-area(r2)-2*area(r3);
printf("%1f",redarea);
return 0;
}
// 求阶乘
long jiecheng(int num){
long result=1,i;
for(i=1;i<=num;i++){
result*=i;
}
return result;
}
int main(int argc, char *argv[]) {
int j;
long res=0;
for(j=0;j<=5;j++){
res+=jiecheng(j);
}
printf("1!+2!+3!+4!+5!=%d",res);
return 0;
}```
```c
// 求阶乘
long jiecheng(int num){
long result=1,i=1;
for(;i<=num;i++){
result*=i;
}
return result;
}
int main(int argc, char *argv[]) {
// int j;
double res=1,j=1;
for(;j<=10;j++){
res+=1.0/jiecheng(j);
}
printf("1+1/1!+1/2!+1/3!+1/4!+1/5!...=%f",res);
return 0;
}
边栏推荐
- 爬虫相关文章收藏:pyppeteer 、Burpsuite
- Install new version cmake & swig & tinyspline
- [trajectory planning] testing of ruckig Library
- 测试须知——常见接口协议解析
- Halcon photometric stereoscopic
- The most complete and simple nanny tutorial: deep learning environment configuration anaconda+pychart+cuda+cudnn+tensorflow+pytorch
- GAN Inversion: A Survey
- Redis 新手入门
- Flutter's brain map notes are easy to find and search!
- c语言语法基础之——指针( 多维数组、函数、总结 ) 学习
猜你喜欢

Redis novice introduction

2021-11-22 运动规划杂记

logback

MapReduce&Yarn理论

Badge series 7: use of codacy

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

How to create an IE tab in edge browser

Edge computing is the sinking and extension of cloud computing capabilities to the edge and user sides

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

install opencv-contrib-dev to use aruco code
随机推荐
Classified catalogue of high quality sci-tech periodicals in the field of computing
Halcon photometric stereoscopic
我的创作纪念日
Logview Pro can be used if the log is too large
Collection object replication
"One week's data collection" -- combinational logic circuit
online trajectory generation
Regular expression learning
Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
Creation and use of XSync synchronization script (taking debian10 cluster as an example)
Force buckle ----- remove the maximum and minimum values from the array
My creation anniversary
Differences between VI and vim and common commands
Kubernetes cluster deployment (v1.23.5)
Learning to Generalize Unseen Domains via Memory-based Multi-Source Meta-Learning for Person Re-ID
【CVPR 2021】Unsupervised Multi-Source Domain Adaptation for Person Re-Identification (UMSDA)
Logical English structure [key points]
【CVPR 2021】Unsupervised Pre-training for Person Re-identification(UPT)
[pulsar learning] pulsar Architecture Principle
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)