Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

java program to sum following series

0 votes
asked Nov 14, 2018 by fatimah

Write a java program that prints the summary of the following series: 1 + 1/2 + 13 +. . . + 1 / n Using while statement. Get the value for n from the user

1 Answer

0 votes
answered Nov 18, 2018 by Nelson (180 points)
// C++ VERSION

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int n;
    cout << "N = ";
    cin >> n;
    
    float sum = 0;
    
    while (n > 0)
    {
        sum += 1.0/n;
        n--;
    }
    
    cout << "Sum: " << sum;

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...