当前位置:网站首页>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;
}
边栏推荐
- Throttling, anti chattering, new function, coriolism
- What you need to know to test -- URL, weak network, interface, automation
- Edge computing is the sinking and extension of cloud computing capabilities to the edge and user sides
- LeetCode 接雨水系列 42.(一维) 407.(二维)
- 逻辑英语结构【重点】
- Collection object replication
- 测试须知——常见接口协议解析
- Leetcode basic calculator 224 227. follow up 394
- Wechat official account reported error 10003
- Upgrade idea to 2021.2 shortcut keys
猜你喜欢
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程
【轨迹规划】Ruckig库的测试
計算領域高質量科技期刊分級目錄
[pulsar learning] pulsar Architecture Principle
How does flutter transfer parameters to the next page when switching pages?
Badge collection 6:api\_ Use of level
软件测试---如何选择合适的正交表
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
mysql 数据库字段查询区分大小写设置
Catalogue gradué de revues scientifiques et technologiques de haute qualité dans le domaine de l'informatique
随机推荐
Curriculum learning (CL)
【CVPR 2021】Joint Generative and Contrastive Learning for Unsupervised Person Re-identification
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
pcl install
Introduction to QPM
GAN Inversion: A Survey
同花顺炒股软件安全性怎样?在同花顺怎么开户
Deep learning (tentsorflow2. version) three good student performance problems (1)
"One week's data collection" -- combinational logic circuit
The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
我的创作纪念日
Redis novice introduction
LeetCode 接雨水系列 42.(一维) 407.(二维)
LeetCode 958. Completeness checking of binary tree
QPM performance monitoring components - General
A Style-Based Generator Architecture for Generative Adversarial Networks
SQL高级教程
How to create an IE tab in edge browser
install opencv-contrib-dev to use aruco code
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)