当前位置:网站首页>[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;
} 边栏推荐
- C语言:浅谈各种复杂的声明
- Leftmost prefix principle of index
- Idea small settings
- 不会就坚持63天吧 最大的异或
- Implementation of jump connection of RESNET (pytorch)
- [hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
- 不会就坚持61天吧 最短的单词编码
- Actual combat of flutter - DIO of request encapsulation (II)
- post导出数据,返回
- 10. Fallback message
猜你喜欢

Pytoch automatic mixing accuracy (AMP) training

恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会

Deep learning training strategy -- warming up the learning rate

Use of construction methods

不会就坚持64天吧 查找插入位置

There are objections and puzzles about joinpoint in afterreturning notice (I hope someone will leave a message)

Webrtc realizes simple audio and video call function

顺序表和链表

VScode 一键编译和调试

15.federation
随机推荐
Not for 60 days, magical dictionary
Log configuration logback
Leftmost prefix principle of index
C语言力扣第61题之旋转链表。双端队列与构造循环链表
用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
Implementation of jump connection of RESNET (pytorch)
Flutter实战-请求封装(二)之dio
Interview notes of a company
Model tuning, training model trick
Introduction and examples of parameters in Jenkins parametric construction
Locker 2022.1.1
Whether the modification of import and export values by ES6 and commonjs affects the original module
不会就坚持59天吧 替换单词
Mpc5744p introduction and opensda firmware update
oracle 更新和删除数据
LeetCode_ Stack topics
Realize the effect of univariate quadratic equation through JS. Enter the coefficients of a, B and C to calculate the values of X1 and x2
There are objections and puzzles about joinpoint in afterreturning notice (I hope someone will leave a message)
Webrtc realizes simple audio and video call function
JVM (heap and stack) memory allocation