Question

It is my question : how to write the formula of hoarmnic numbers in vba {1+1/2+1/3+1/4+....)...

It is my question :

how to write the formula of hoarmnic numbers in vba {1+1/2+1/3+1/4+....)

the sum is 10 and i would like to find the terms .....

Another question :

thanks a lot

First Question :

You don't need to write the formula. Simply use for loop and a variable of double type to add the values in to your final sum. Please find below program to understand it more.

Second Question :

Below is the program to find out sum of first n harmonic terms.

``````using System;
public class Exercise19
{
public static void Main()
{
int i,n;
double s=0.0;

Console.Write("\n\n");
Console.Write("Calculate the harmonic series and their sum:\n");
Console.Write("----------------------------------------------");
Console.Write("\n\n");

Console.Write("Input the number of terms : ");
Console.Write("\n\n");
for(i=1;i<=n;i++)
{
Console.Write("1/{0} + ",i);
s+=1/(float)i;
}
Console.Write("\nSum of Series upto {0} terms : {1} \n",n,s);
}
}``````

Earn Coins

Coins can be redeemed for fabulous gifts.