当前位置:网站首页>[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;
} 边栏推荐
- Mpc5744p introduction and opensda firmware update
- 9. Delay queue
- 11. Backup switch
- No, just stick to it for 59 days
- MySQL - clustered index and secondary index
- Idea small settings
- Not for 58 days. Implement prefix tree
- [k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
- Beginner: array & String
- C language: structure simple syntax summary
猜你喜欢

JVM (heap and stack) memory allocation

Christmas tree web page and Christmas tree application

不会就坚持63天吧 最大的异或

不会就坚持65天吧 只出现一次的数字

On the use of pyscript (realizing office preview)

MySQL - clustered index and secondary index

Webrtc realizes simple audio and video call function

Beginner: array & String

用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案

Not for 58 days. Implement prefix tree
随机推荐
Introduction and examples of parameters in Jenkins parametric construction
The daily life of programmers
Wechat applet parameter transfer
leetcode 686.重复叠加字符串 KMP方法(C语言实现)
TypeError: Cannot read properties of undefined (reading ‘then‘)
TypeError: Cannot read properties of undefined (reading ‘then‘)
14.haproxy+keepalived负载均衡和高可用
Interview notes of a company
10.回退消息
(.*?) regular expression
C language: structure simple syntax summary
不会就坚持58天吧 实现前缀树
不会就坚持60天吧 神奇的字典
Exception resolution: error of not finding edu.stanford.nlp.semgraph.semgrex.semgrexpattern in cococaption package
String, array, generalized table (detailed)
Coding questions encountered in the interview
不会就坚持68天吧 狒狒吃香蕉
kotlin的List,Map,Set等集合类不指定类型
Unity基础(3)—— unity中的各种坐标系
Record the Niua packaging deployment project