C programming help - adding values together/for loop -
i'm trying add values using loop i'm stumped how it. code have far:
float counter; float harmonic; float sum; (counter = 2; counter <= n; counter ++) { harmonic = 1/counter; // current value sum = harmonic; // stores current value } return 0; }
so each value "harmonic" variable need add next until loop ends. should looking @ arrays? help.
change code read
float sum = 0;
then inside loop write
sum += harmonic;
you don’t need array unless want remember of values you’ve summed.
also, don’t use float
loop counter. want int
instead.
Comments
Post a Comment