09-18-2016 10:53 PM
I want to write a program that gets a user-input integer, and adds up the even numbers between 0 and that integer. So if 8 is inputed, the program returns 20 (=2+4+6+8). If 7, the program returns 12=(2+4+6). I know i need to use a loop, but not sure how to make it use the even numbers and find the sum
09-18-2016 11:05 PM
Write down in words on a piece of paper how you'd do it.
A tip for LabVIEW is to use the Quotient & Remainder function. If you use that to divide a number by 2, it is even if the remainder is =0.
Another though, divide by 2. Take the quotient and add up all the values. Then multiply that by 2.
09-18-2016 11:40 PM
Its Seems to be your homework, As suggested by ravens
Study about the behaviour of following Functions
R&Q (If R=0 Even)
For Loop(to Run for Given Integer times)
Conditional Indexing in for Loop (To index into array only if R=0)
Arrays(To Add Array Elements )
09-19-2016 06:56 AM
I would use Quotient & Remainder to get the number of loop iterations needed. Then use a FOR loop with a shift register to keep the sum in. So each iteration you add (i+1)*2.
09-19-2016 07:59 AM
@crossrulz wrote:I would use Quotient & Remainder to get the number of loop iterations needed. Then use a FOR loop with a shift register to keep the sum in. So each iteration you add (i+1)*2.
@just Implementation is mine (Idea belongs to you @ Crossrulz)
09-19-2016 08:22 AM
09-19-2016 08:24 AM
Guys, this is an obvious homework. Do not do the work for them! They will never learn otherwise.
09-19-2016 08:26 AM
No loop needed, just do the math!
(Hint: Search for the little Gauß)
09-19-2016 08:34 AM
09-21-2016 09:10 AM
Solve for the formula, then use an Expression Node.