I am having difficulty with an assignment that has to deal with recursion in C.
We were asked to create a program (using recursion) to sum up a harmonic series.
This is what I have so far:
Code:
#include <stdio.h>
long Harmonic ( int n );
int main()
{
int seriesSize;
printf("This program prints a harmonic series.\n");
printf("How many numbers do you want?\n");
scanf("%d", &seriesSize);
printf ("The sum of this harmonic series is: " "%ld\n", Harmonic(seriesSize));
system("pause");
}
long Harmonic ( int n )
{
long result;
if ( n == 0 )
result = 1;
else
result =(Harmonic(n-1)+(1/n));
return result;
}
I am having trouble with the output, it doesn't return the correct value.
Is my harmonic equation incorrect? Where am I going wrong?
Thanks for your help in advance!
~AB