当前位置:网站首页>Recursively find the partial sum of simple alternating power series (15 points)
Recursively find the partial sum of simple alternating power series (15 points)
2022-07-22 18:49:00 【Canned】
6-12【 Extended programming problems _ Practice after class 】【 Chen Yue textbook exercises 2.6】 Recursively find the partial sum of simple alternating power series (15 branch )
This question requests to realize a function , Calculate the partial sum of the following simple alternating power series :
Function interface definition :
double fn( double x, int n );
The title guarantees the incoming n It's a positive integer. , And the input and output are in the double precision range . function fn The partial sum of the above series should be returned . It is recommended to try to implement .
Sample referee test procedure :
#include <stdio.h>
double fn( double x, int n );
int main()
{
double x;
int n;
scanf("%lf %d", &x, &n);
printf("%.2f\n", fn(x,n));
return 0;
}
/* Your code will be embedded here */
sample input :
0.5 12
sample output :
0.33
This problem tries to find rules by mathematical induction in order to use recursion ,
Then, inexplicably, we get the following formula .... Cry
Code :
double fn(double x, int n)
{
if (n == 1)return x;
else{
return -fn(x,n - 1) * x + x;
}
}
边栏推荐
- Parameter index out of range (1 &gt; number of parameters, which is 0).
- 【Nordic】nRF52810 OTA升级(二)–DFU如何使用
- 1.常量中有换行符Qt5-》vs的解决方案;2.同一份代码Qt和vs共同编译的问题和解决方案
- C language simple TCP server program
- 07.合成复用原则(Composite/Aggregate Reuse Principle,CARP)
- PAT乙级1020月饼(注意测点)
- Summary 20220214
- 05.迪米特原则(Law of Demeter LoD)
- PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so'
- JSON序列化对象时,如何返回有空值的带属性名称json字符串?
猜你喜欢
Go 语言重要知识点:字符串、UTF-8 编码、rune
【Audio】I2S传输PCM音频数据分析总结(二)
win10sp1升到最新版本;QT5.9.6静态编译(network有效)
1.通过类似window路径的方式访问json
LeetCode 105. 从前序与中序遍历序列构造二叉树
递归求简单交错幂级数的部分和 (15分)
PTA 基础题7-28猴子选大王(简单方法)
04. interface aggregation principle
Interview experience of Android Internet manufacturers
05.迪米特原则(Law of Demeter LoD)
随机推荐
ECSHOP disable cache and close cache
1.QTableWidget插入按钮,灵活删除本行,一列显示行号
LeetCode 654. 最大二叉树
LeetCode: 197. 上升的温度
PAT基础习题集7-26 单词长度(精简代码)
App mobile End test [6] application (APK) package Management and Activity
Codeforces Round #805 (Div. 3)(8/8)
Simple demonstration and prevention of CSRF attack in PHP development
Protocol and port
[Nordic] nrf52810 OTA upgrade (III) – DFU theoretical analysis
【 sdio】 résumé de l'analyse du Protocole sd2.0 (Ⅲ) - - Introduction aux commandes pertinentes de la carte SD
ECSHOP configures wechat payment, and the wechat developer tool prompts "unbound web developer" when wechat payment pops up
[SDIO] sd2.0 protocol analysis summary (I) -- Introduction to SD card basic probability
Go 语言学习:Go 语言之旅(四)
App移动端测试【6】应用程序(apk)包管理与activity
PAT乙级1010一元多项式求导(题意理解)
解决不能维持IntelliJ 之 Target bytecode Version版本号
bjyx
练习7-4 找出不是两个数组共有的元素(C语言)
App移動端測試【6】應用程序(apk)包管理與activity