21. Program to calculate and display the sum of the following series using for loop: 1/2 + 2/3 + 3/4 + ... + 99/100

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 21:

Write a program to calculate and display the sum of the following series using for loop:
1/2 + 2/3 + 3/4 + ... + 99/100

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    float n1, n2, sum=0;
    for(n1=1,n2=2;n2<=100;n1++,n2++)
    {
        sum=sum+(n1/n2);
    }
    cout<<"\nSum of the series is:"<<sum;
    getch();  
}

Let me know in the comment section if you have any question.

Previous Post:
20. Program to calculate and display the sum of the following series using for loop: 1 + 2x + 3x^2 + 4x^3 + 5x^4

Comments