LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sum of first N odd numbers using a while loop

How do I make a program where we can input a number N, so it adds up all odd numbers from 0 to N, using a while loop. For example, if 11 is inputted, then the program returns 36 (1+3+5+7+9+11). Please help me

0 Kudos
Message 1 of 2
(1,473 Views)

What have you tried? What is the problem? How would you solve it with paper&pencil?

Do you have problem generating the numbers?

Do you need to determine if a number is odd or do they occur in some regular pattern?

Can you generate the numbers, but don't know how to sum them?

A FOR loop is probably a better choice because (given N) the total number of iterations can be calculated before the loop starts.

Have a look at the training resources listed on the top of the forum.

 

0 Kudos
Message 2 of 2
(1,425 Views)