I am trying to sum up the product of the numbers from the begining to the last number of my set of numbers, such as begining = 1 and end = 5, given a change of = 1 I want to do 1*2*3*4*5, I want to use a forloop and have started off with for (int i = begining; i <= last; i+=change), I know that i need to do i*i+delta+i*delta, and I need to do a nested for statement right? But i have no clue how to set up the inner loop
for (int i = start; i <= end; i+=delta)
Meant to use this
double total = 0;
(int i = begining; i <= last; i+=change)
I'm sorry, I don't quite understand your question. You say that you want the sum of the products of numbers, and you gave the example of 1*2*3*4*5. So that is one of the terms of the sum, what are the other terms?
In other words:
1 * 2 * 3 * 4 * 5 +
What are the question marks supposed to be filled with?
Since i becomes the value through the iteration of the loop, can't you just create a variable initialized to 1 that holds itself * i until the loop completes, leaving your new variable holding the result?
Yes, just like the way you accumulated the value of sum in your for loop in your old question in the Java Forum: http://www.dreaminco...make-this-loop/ , you would accumulate the product in your for loop now.
If i were to change this loop for it to accept a begining numbers greater than a ending number, how would i do that, how can I put an or statement in the for loop? such that my start would be 5 and end would be 1 and change -1, becuase the one I have now would be false in this case, is there a way to do an or statement in a for statement?
what im trying to ask is that I need a loop that will work for both if begining was 5 and end was 1 and if begining was 1 and end was 5?