当前位置:网站首页>2.4 finding the sum of the first n terms of the interleaved sequence
2.4 finding the sum of the first n terms of the interleaved sequence
2022-06-25 19:57:00 【Then peace and happiness】
This question requires the preparation of procedures , Calculate interleaved sequence 1-2/3+3/5-4/7+5/9-6/11+… Before N Sum of items .
Input format :
Input gives a positive integer on a line N.
Output format :
Output the value of the partial sum in one line , The result is three decimal places .
sample input :
5
sample output :
0.917
Reference code :
#include<stdio.h>
int main(void)
{
int i, flag, b, d, n;
double sum;
scanf("%d", &n);
sum=0; flag=1;d=1;b=1;
for(i=1; i<=n; i++)
{
sum=sum+b*flag*1.0/d;
flag=flag+1;
b=-b;
d=d+2;
}
printf("%.3f", sum);
return 0;
}
边栏推荐
- 2.15(Multiple of 3 Or 5)
- PAT B1061
- Determine whether it is a web page opened on wechat
- Arduino : No such file or directory
- Tcp/ip test questions (III)
- Analyse du code source du processus d'acquisition et de connexion hikaricp II
- Google SEO external chain releases 50+ website platform sharing (e6zzseo)
- DARKHOLE 2
- 2、 Hikaricp source code analysis of connection acquisition process II
- Mail monitoring cloud script execution progress
猜你喜欢

What should I pay attention to in GoogleSEO content station optimization?

Wechat applet swiper simple local picture display appears large blank

2020-12-09 laravel . Env file loading mechanism process

Vulnhub range - correlation:2

Mqtt+ardunio+esp8266 development (excluding mqtt server deployment)

rmi-registry-bind-deserialization

Apifox simple understanding -- the integrator of web side testing

One night I worked as an XPath Terminator: XPath Helper Plus

Ali visual AI training camp -day05- creativity day - your image recognition project

Yaml configuration
随机推荐
Wechat applet cloud function does not have dependency option installed
PAT B1061
Force wechat page font size to be 100%
2.14(Knight Moves)
Laravel validation rule followed Role of auth:: id()
Validation of TTF font by validator of laravel
1、 Hikaricp source code analysis of connection acquisition process I
Trend ea- fixed stop loss and profit per order
From now on, I will blog my code
Go language installation and uninstallation
wooyun-2014-065513
Bindgetuserinfo will not pop up
Arduino read temperature
New features of php7
Can the stock account opened through qiniu school be used? Is the fund safe?
PostgreSQL change table owner
What are Baidu collection skills? 2022 Baidu article collection skills
5、 Initialization analysis II of hikaricp source code analysis
Network security detection and prevention test questions (II)
Dependency injection in PHP reflection implementation framework