程序将连续的int值找到输入数字的总和 [英] program to find consecutive int values to the sum of inputted number

查看:62
本文介绍了程序将连续的int值找到输入数字的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目将为您提供有关嵌套for循环和用户定义函数的更多经验。最初的项目来自IT公司的编程测试,他们要求最有效的代码来解决一个问题。对于这项任务,我们只关注代码的正确性,不会考虑代码效率。





背景



某些数字可以表示为n(n> = 2)个连续正整数的总和。例如:



15 = 1 + 2 + 3 + 4 + 5


15 = 4 + 5 + 6


15 = 7 + 8



给定一个数字,你的程序应该能够找出所有正确的解决方案,并在屏幕上打印出来。每个解决方案中的数字应按升序打印。如果找到多个有效的解决方案,应根据每个解决方案中的第一个数字来订购所有解决方案。


程序将首先要求用户输入一个数字,然后它将使用嵌套for循环查找并打印输入数字的所有有效解决方案。每个有效的解决方案都应该输出为样本可执行文件中的总和。有效解决方案的总数也会计算并输出。

This project will give you more experience on nested for loops and user-defined functions. The original project came from an IT company?s programming test where they were asking for the most efficient code to solve one problem. For this assignment we only focus on the correctness of our code and will not consider code efficiency.





Background



Some numbers can be expressed as the sum of n (n>=2) consecutive positive integers. For example:



15=1+2+3+4+5

15=4+5+6

15=7+8



Given a number, your program should be able to find out all the correct solutions, and print them out on the screen. Numbers within each solution should be printed in ascending order. If more than one valid solution found, all the solutions should be ordered according to the first number within each of them.

The program will first ask user to input a number, then it will use nested for loops to find and print out all the valid solutions for the number entered. Each valid solution should be output as a sum as done in the sample executable. The total number of valid solutions is also counted and output.

推荐答案

这是您正在尝试做的事情,还是您向社区提出的问题?
Is this something you are trying to do, or a problem you are presenting to the community?



这是您正在尝试做的事情,还是您向社区提出的问题?
Is this something you are trying to do, or a problem you are presenting to the community?



只需要帮助就如何开始

just need help on how to get started


我也查看了这个描述并且似乎无法提出任何排序解决方案想出一些东西来添加连续的整数以等于输入的数字
ive looked over this description also and cant seem to come up with any sort of solution to come up with something to add consecutive intergers to equal the number that is inputted


这篇关于程序将连续的int值找到输入数字的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆