Hello. I am having trouble with one of my labs in my programming class. It seems to be simple and to the point, but I'm not sure if I understand it all. This is the question:

Write a program to compute the partial sum of harmonic series

1 + 1/2 +1/3 + ... + 1/n

and display the intermediate partial sums. Hint: use a for loop.

This is what I came up with. I know it's not 100% correct, but I got myself stated, I just need a push in the right direction.

#include <stdio.h>

int main (void)

{

int n;

printf("Enter a number:");

scanf("%d", &n);

int i, sum = 0;

for (i=1; i<=n; i=i+1)

{

sum = sum + (i * i);

}

printf ("The intermediate partial sums are:\n", sum);

return(0);

}

thank you in advance

You've got the gist of it , but there's some fairly fundamental problems:

When is your printf going to be called? Is it really going to show intermediate sums? And how does you printf know how you want variable sum display as?

If sum is representing fractions is int an appropriate type?

In your scanf why is the address of memory location 'n' useful (hint: it isn't!)

Is your formula in the loop reflecting the one in the question (I think you're missing the 'one over' part).

Hope that gives you some things to think about!

EDIT - sorry, thought there were no replies before I posted? A fair few of my points have already been covered.