Write a program in c++ to calculate the sum of the following series
sum=1/2+2/3+3/4+.........+n/(n+1)
Answers
Explanation:
vAGRA: An armed man with a criminal background held at least 22 children hostage on Thursday after luring them to his daughter’s 'birthday party'. Later, he hurled a crude bomb and also fired shots from a country-made pistol on local villagers and y
Following are the code in c++ language for the above question:
Explanation:
#include <iostream> //header file.
using namespace std;
int main() //main function definition.
{
float size,i=1,j=2,Total=0; //variable declaration.
cout<<"Enter the size of the series"; //print the message to the user.
cin>>size;//take the input from the user.
while(i<=size) //while loop
{
Total=Total+(i/j);//sum the value of the series.
i++; //increase opearation for numerator.
j++;//increase opeartion for denomenator.
}
cout<<Total; //print the total value.
return 0; //return statement.
}
Output:
- If the user inputs 1 then the output is 0.5.
- If the user inputs 2 then the output is 1.16667.
Code Explanation:
- The above code is written in c++ language which gives the total value of the above-defined series.
- The size of the series is given by the user and the while loop iterates the series up to user size and then prints the sum of the series.
Learn More:
- Programs : https://brainly.in/question/9996665