当前位置:网站首页>Zzuli:1041 sum of sequence 2
Zzuli:1041 sum of sequence 2
2022-07-03 14:33:00 【Snake_____】
Title Description
Enter an integer n, Output sequence 1-1/3+1/5-…… front n Sum of items .
Input
Enter only one integer n.
Output
The result is reserved 2 Is a decimal , Take a line alone .
The sample input Copy
3
Sample output Copy
0.87
#include <stdio.h>
int main()
{
int n,i,sign=1;
double t,term,sum=1,deno=3;
scanf("%d",&n);
if(n!=0)
{
for(i=1;i<n;i++)
{
t=1/deno;
sign=(-1)*sign;
term=sign*t;
deno=deno+2;
sum=sum+term;
}
printf("%.2lf",sum);}
else
printf("0.00");
return 0;
}
边栏推荐
- Accelerating strategy learning using parallel differentiable simulation
- MySQL multi table query subquery
- 数学常数表 by q779
- GRPC的四种数据流以及案例
- puzzle(016.4)多米诺效应
- 【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
- Puzzle (016.4) domino effect
- 洛谷P5194 [USACO05DEC]Scales S 题解
- 6-9 statistics of single digits (15 points)
- 7-16 find the set of integers that meet the given conditions
猜你喜欢
Eight sorts
Analysis of gene family characteristics - chromosome location analysis
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
retrofit
编程语言:类型系统的本质
剑指 Offer 28. 对称的二叉树
How to query the baby category of tmall on Taobao
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
表单文本框的使用(一) 选择文本
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
随机推荐
关于敏捷的一些概念
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Solr series of full-text search engines - basic principles of full-text search
论文分享:Generating Playful Palettes from Images
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
Understanding of closures
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
7-14 sum integer segments (C language)
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
retrofit
Luogu p4047 [jsoi2010] tribal division solution
7-18 finding the single root of polynomial by dichotomy
7-2 and then what time (15 minutes)
适用于XP的DDK
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
Tonybot humanoid robot checks the port and corresponds to port 0701
牛客网:过河卒
puzzle(016.3)千丝万缕
7-23 currency conversion (using array conversion)
Sword finger offer 28 Symmetric binary tree