当前位置:网站首页>[c language] PTA 7-51 sum the first n terms of odd part sequence
[c language] PTA 7-51 sum the first n terms of odd part sequence
2022-07-29 04:29:00 【LastWhisperw】
This question requires the preparation of procedures , Calculation sequence 1 + 1/3 + 1/5 + ... Before N Sum of items .
Input format :
Input gives a positive integer on a line N.
Output format :
In a row, press “sum = S” The format of the output part and the value of S, Accurate to the decimal point 6 position . The calculation results should not exceed the double precision range .
sample input :
23No blank lines at the end
sample output :
sum = 2.549541No blank lines at the end
Be careful sum The type of is a real number . If i Integers , It cannot be written as 1/(2*i-1).
#include<stdio.h>
int main(){
int N;
double sum=0;
double i;
scanf("%d",&N);
for(i=1;i<=N;i++){
sum=sum+1.0/(2*i-1);
}
printf("sum = %.6f",sum);
return 0;
} 边栏推荐
- No, just stick to it for 59 days
- Coding questions encountered in the interview
- Machine vision series 3:vs2019 opencv environment configuration
- 15.federation
- Class starts! See how smardaten decomposes complex business scenarios
- Mongo Shell交互式命令窗口
- Dabao and Erbao
- es6和commonjs对导入导出的值修改是否影响原模块
- Common components of solder pad (2021.4.6)
- Redux quick start
猜你喜欢

String, array, generalized table (detailed)

Record of problems encountered in ROS learning

14.haproxy+keepalived负载均衡和高可用

15.federation

Definition and implementation of stack and queue (detailed)
![[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)](/img/fe/8c707c30c734de7bb76ea68134842c.png)
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)

6. Pytest generates an allure Report

10. Fallback message

Class starts! See how smardaten decomposes complex business scenarios

The third ACM program design competition of Wuhan University of Engineering
随机推荐
oracle 更新和删除数据
Shell string segmentation
9.延迟队列
Log configuration logback
Leftmost prefix principle of index
不会就坚持69天吧 合并区间
Integration of Nan causes in pytorch training model
kotlin的List,Map,Set等集合类不指定类型
Beginner: array & String
Not for 61 days. The shortest word code
6.pytest生成allure报告
使用容器部署Jenkins
12. Priority queue and inert queue
Differences and principles of bio, NiO and AIO
C语言:联合体知识点总结
The pit I walked through: the first ad Sketchpad
leetcode 686.重复叠加字符串 KMP方法(C语言实现)
Not for 60 days, magical dictionary
9. Delay queue
Machine vision series 3:vs2019 opencv environment configuration