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

Popular posts from this blog

c# - How to get the current UAC mode -

angularjs - ng-repeat duplicating items after page reload -

javascript - What's causing this slow/delayed audio playback in Safari? -