Let's assume that you want the sum of the general harmonic series:
sum(n=0,inf): 1/(an+b)
Since we know that the harmonic series will converge to infinity, we'll also assume that you want the sum from 0 to n.
double genHarmonic(const double n, const double a, const double b) {
double sum = 0.0;
// perform calculations
int k;
for(k = 0; k <= n; ++k) {
sum += 1.0 / (a * k + b);
}
return sum;
}
Chat with our AI personalities
Class HarmonicSeries{
public static void main(String args[]){
int num = Integer.parseInt(args[0]);
double result = 0.0;
while(num > 0){
result = result + (double) 1 / num;
num--;
}
System.out.printl of Harmonic Series is "+result);
}
}
Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11
sum = 0; for (int i = 12; i
As you can see, this series is the sum of the sequence: 1, 2, 3, 4, 5, 6. That is to say: 1 + 2 = 3 3 + 3 = 4 6 + 4 = 10 10 + 5 = 15 15 + 6 = 21 To program this in C, you would want a simple incremental counter which would be added to the series sum on each iteration of the loop. { int c = 2; int sum = 1; // loop until you find all the numbers you want while(1) { // increase the running sum to find the next next number in the series sum += c; // increment our counter ++c; } }
The name of the program. For example: program sum ! This is a comment. Your program's code goes here... end program sum
int sum (int min, int max) {return (max-min+1)*(max+min)/2;}