当前位置:网站首页>[C language] PTA 7-52 finding the sum of the first n terms of a simple interleaved sequence
[C language] PTA 7-52 finding the sum of the first n terms of a simple interleaved sequence
2022-07-29 04:29:00 【LastWhisperw】
This question requires the preparation of procedures , Calculation sequence 1 - 1/4 + 1/7 - 1/10 + ... 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 three decimal places . The calculation results should not exceed the double precision range .
sample input :
10No blank lines at the end
sample output :
sum = 0.819No blank lines at the end
#include<stdio.h>
int main(){
int N;
double sum=0;
double i;// The first i term
scanf("%d",&N);
int sign=1;// Symbol
for(i=1;i<=N;i++){
double a;
a=1/(3*i-2);
sum=sum+sign*a;
sign*=-1;
}
printf("sum = %.3f",sum);
return 0;
} 边栏推荐
- C language force buckle question 61 of the rotating list. Double ended queue and construction of circular linked list
- Leftmost prefix principle of index
- MySQL - 聚簇索引和辅助索引
- Pix2.4.8 from start to installation (2021.4.4)
- Interview notes of a company
- C language: summary of consortium knowledge points
- pyscript无法引入包
- Flutter实战-请求封装(二)之dio
- 异常解决:cococaption包出现找不到edu.stanford.nlp.semgraph.semgrex.SemgrexPattern错误
- 12. Priority queue and inert queue
猜你喜欢
随机推荐
Sequence list and linked list
不会就坚持66天吧 权重生成随机数
Laya中的A星寻路
Oracle update and delete data
The daily life of programmers
Record of problems encountered in ROS learning
Pyscript cannot import package
6. Pytest generates an allure Report
It won't last for 70 days. The k-largest number in the array
The principle of inverse Fourier transform (IFFT) in signal processing
The third ACM program design competition of Wuhan University of Engineering
11.备份交换机
Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
Visio draw grid
Whether the modification of import and export values by ES6 and commonjs affects the original module
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
恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
Won't you insist on 71 days? List sorting
14. Haproxy+kept load balancing and high availability
Unity基础(3)—— unity中的各种坐标系









