《编程求1+1/2+1/3+...+1/n》 题解

Python编程PTA题解——求分数序列前N项和 Description:计算序列 2/1+3/2+5/3+8/5+… 的前N项之和。注意该序列从第2项起,每一项的分子是前一项分子与分母的和,分母是前一项的分子。 Input:输入仅一行,输入一个正整数N。 Output:输出仅一行,输出部分和的值,精确到小数点后两位。题目保证计算结果不超过双精度范围。 Sample Input:20 Sample Output:32.66 ... 阅读详情

描述

编程求1+1/2+1/3+…+1/n

这题是一道简单的循环题,直接用1去除n以内的数,然后相加就行了;

下面出示代码:

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
	float a,b=1,c=2;
	cin>>a;
	do{
	b=b+1/c;
	c++;
	}while(c<=a);
	cout<<fixed<<setprecision(3)<<b;
	return 0;
}

信奥题解:Recamán 序列 来源:2024年12月GESP C++四级编程第一题。本文分析官方的标准答案,并给出了现代C++的参考代码。文章还介绍了有趣的 Recamán 数列:一种在数学和编程中具有趣味性和启发性的数列。它简单的定义与复杂的行为使其在教育、艺术和数论研究中展现出独特的价值。最后给出了使用 Recamán 数列生成的图形和音乐。 阅读详情

相关推荐

题解:洛谷 B2142 求 1+2+3+...+N 的值

等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。本文分享的必刷题目是从。#入门# #语法基础#

团爸讲算法 704

PTA4

4.水仙花数是指一个n位正整数(n≥3),它的每位数字的n次幂之和等于它本身。5.输入一个正整数n(1≤n≤9),打印一个高度为n的、由“*”组成的等腰三角形图案。6. 输入一个正的奇数n(1≤n≤9),打印一个高度为n的、由“*”组成的正菱形图案。8.输入一个非负整数,从高位开始逐位分割并输出它的各位数字。7. 输入一个正整数n(1≤n≤10),打印一个n行n列的方阵。)的功能是:输入一批整数,用负数作为输入的结束标志,统计其中大于85的数据个数。(1≤n≤10),输出n×n的简易乘法表。

m0_73925458的博客 3343

【算法】求1+2+3+...+n

描述求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。数据范围:0n≤200进阶: 空间复杂度O(1)O(1)O1,时间复杂度O(n)O(n)On示例1示例2。

九师兄 348

【入门】编程求1+1/2+1/3+...+1/n

【代码】【入门】编程求1+1/2+1/3+...+1/n

2301_76723927的博客 2524

c++求1+1/2+1/3+...+1/n

题目描述 编程求1+1/2+1/3+...+1/n 输入 输入:输入一行,只有一个整数n(1<=n<=200) 输出 输出:输出只有一行(这意味着末尾有一个回车符号),包括1个实数。(保留3位小数) 样例输入 Copy 5 样例输出 Copy 2.283

publisher与subscriber话题的消息类型md5sum不一致问题

[ERROR] [1604235557.591296096]: Client [/range_vision_fusion_01] wants topic /detection/vision_objects to have datatype/md5sum [autoware_msgs/DetectedObjectArray/13415342e539aa36ea9a6f04ffaf39b4], but our version has [autoware_msgs/DetectedObjectArray/c16a

cxhmike的博客 6619

c语言用do-while语句计算1+1/2+1/3+……+1/n。

【代码】c语言用do-while语句计算1+1/2+1/3+……+1/n。

2302_76436844的博客 3906

mipi deskew原理理解

何为skew, 从字面意思看是倾斜了,不对齐了;放在mipi的传输中意思就是clock lane和data lane 及data lane与data lane间出现了相位差;一旦出现相位差,大家采样数据时就可能不在同一个节拍上,会出现传输错误。所以就要做deskew,通过做deskew来使得大家重新对齐,在同一个节奏下传输数据. 一般当data rate高于1.5G时建议开启deskew。

lx123010的专栏 8092

编程求1+1/2+1/3+...+1/n

输出只有一行(这意味着末尾有一个回车符号),包括1个实数。输入一行,只有一个整数n(1<=n<=200)编程求1+1/2+1/3+…

c++练习生 823

保姆级教程:用ROS2 Humble和Nav2从零搭建一个能自主导航的机器人小车(含SLAM建图与避障)

本文提供了一份详细的保姆级教程,指导如何使用ROS2 Humble和Nav2从零搭建一个具备自主导航功能的机器人小车,包括SLAM建图与避障。教程涵盖了硬件组装、ROS2环境配置、URDF模型创建、SLAM建图实战、Nav2导航栈配置以及系统集成调试等关键步骤,适合机器人开发初学者和进阶开发者。

weixin_30329623的博客 490

SATA硬件电路设计实战:从接口规范到高速布线技巧

本文深入探讨了SATA硬件电路设计的核心要点与实战技巧。从接口物理电气规范、AC耦合电容与阻抗控制等基础,到FPGA/SoC高速收发器选型配置,再到应对6Gbps高速信号的PCB布局布线艺术,系统性地解析了SATA电路设计中的关键挑战与解决方案,助力工程师规避常见陷阱,实现稳定可靠的存储接口设计。

tech5的博客 530

Python编程PTA题解——求交错序列前N项和(1-2/3+3/5-4/7+5/9-6/11+…...)

Description:计算交错序列 1-2/3+3/5-4/7+5/9-6/11+… 的前N项之和。 Input:输入仅一行,输入一个正整数N。 Output:输出仅一行,输出部分和的值,结果保留三位小数。 Sample Input:5 Sample Output:0.917 ...

美好事物 1万+

【第三方互联】3、腾讯QQ授权第三方登录

当我们创建的 QQ 互联应用成功后,我们便可以开始使用该应用来实现 QQ 互联 一、获取 APP ID 和 APP Key 1、找到我的应用 2、点击应用,进入详情 这样,我们就获取到了 APP ID 和 APP Key 二、进行开发 1、将 APP ID 、APP Key,以及该应用的信息放入项目中的配置文件中,我使用的是SpringBoot,我放在了 application.y...

JACKAL 22万+

Python编程PTA题解——求奇数分之一序列前N项和(1+1/3+1/5......)

Description:计算序列 1 + 1/3 + 1/5 + … 的前N项之和。 Input:输入仅一行,输入一个正整数N。 Output:输出仅一行,按照“sum = S”的格式输出部分和的值S,精确到小数点后6位。题目保证计算结果不超过双精度范围。 Sample Input:23 Sample Output:sum = 2.549541 ...

美好事物 1万+

【AI智能体】Codex 生成高质量电商套图实战操作详解

Codex 生成高质量电商套图实战操作详解

congge 4518

Zemax与Matlab交互:双胶合优化详细流程

Zemax与Matlab交互:双胶合优化详细流程

weixin_72050316的博客 629

练习2-13 求N分之一序列前N项和 (15分)

快速找到所需题目:浙大版c语言程序设计第三版题目集一览表 微信搜索公众号【IT学长】: 回复 :“c-pdf” 免费下载C语言经典100题PDF版本 回复 :“编程交流群”” 进C/C++/Java编程题交流、问题解答群,和大佬一起进步 练习2-13 求N分之一序列前N项和 本题要求编写程序,计算序列 1 + 1/2 + 1/3 + … 的前N项之和。 输入格式: 输入在一行中给出一个正整数N。 输出格式: 在一行中按照“sum = S”的格式输出部分和的值S,精确到小数点后6位。题目

IT学长 2797

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

《编程求1*2*3*...*n》 题解

这题是一个简单的求阶乘的题,只需要把n以内的数全部乘起来就行了;

专门发一些c++题解 134

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

《编程求1+3+5+...+n》 题解

这题是一道简单的循环题,从一开始循环,每次加二到n;编程求1+3+5+…

专门发一些c++题解 332

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

LeetCode 面试题64 求1+2+3+ ...+ n 题解

​​​  题目:求 1+2+…+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 示例 1: 输入: n = 3 输出: 6 示例 2: 输入: n = 9 输出: 45 限制: 1 <= n <= 10000 ​​​  观察题目:不能使用乘除法、for、while、if、else、switch、case等...

qq_40405705的博客 937

Python编程PTA题解——求1!+3!+5!+……+n!

Description:求1!+3!+5!+……+n!的和,要求用循环嵌套设计,n<12。 Input:输入仅一行,输入一个不超过12的正整数n。 Output:输出仅一行,按照格式“n=n值,s=阶乘和”的顺序输出,其中阶乘和是正整数。 Sample Input:5 Sample Output:n=5,s=127 n = int(input()) sum = 0 for i in rang...

美好事物 1万+

《编程求解1+2+3+...+n》 题解

这题是一道简单的循环题,直接从一加到n就行了;编程求解下列式子的值:S=1+2+3+…

专门发一些c++题解 393

计算1+2+3+……+n的值 计算m到n的累加和 Python123超短题解

描述 ‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬ 计算1+2+3+……+n的值 ‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬ 输入格式 ‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪...

qq_61661717的博客 5877

牛客-剑指offer系列题解:求1+2+3+...+n

记录刷题的过程。牛客和力扣中都有相关题目,这里以牛客的题目描述为主。该系列默认采用python语言。 1、问题描述: 求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 2、数据结构: 递归 3、题解: 方法1: # -*- coding:utf-8 -*- class Solution: def __init__(self): self.res = 0 def Sum_Solution

weixin_42042056的博客 302

noi题库 1.6编程基础之一维数组 :题解大礼包20180720

题目传送门 1.6编程基础之一维数组 的全部题解,有需要的同学请自行学习。有任何错漏或者疑问,请留言。谢谢~~~ 1、题目分析 2、代码截图 1.6编程基础之一维数组 编号 题目 相对难度1-5 知识点 1 与指定数字相同的数的个数 2 数组存储+累加 2 陶陶摘苹果 2 经典题 3 计算书费 2 统...

liusu201601的博客 1万+
上一篇: 《编程求1*2*3*...*n》 题解
下一篇: 《编程求1+3+5+...+n》 题解
jiabei2012
博客等级 码龄3年 566粉丝 146原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值