48. JavaScript Program to Compute the 1!/1+2!/2+3!/3+ 4!/4+ …….+n!/n Series.
How does this program work?
- This program is used to find the Sum of the given series 1!/1+2!/2+3!/3+ 4!/4+ …….+n!/n using JavaScript.
- The integer entered by the user is stored in variable n i.e last term for the given series.
- Declare variable sum and Initially initialize with 0, And also Declare another variable fact initialize with 1.
- First we need to calculate the factorial of number after that perormaed by sum for n terms.
Here is the code
<html>
<head>
<title>JavaScript program to Find the Sum of given series</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter any number"> </td>
</tr>
<tr>
<td> <button onclick="series5 ()" >Submit</button> </td>
</tr>
</table>
</body>
<script type="text/javascript">
function series5()
{
var n,i,sum = 0, fact =1,j;
n = parseInt(document.getElementById ("first").value);
document.write("Series till the enter number:</br>");
for(i = 1; i <= n; i++ )
{
fact = fact*i;
j = parseInt(fact/i);
sum = sum+j;
document.write(j + " ");
}
document.write("</br>Sum of the series : "+sum);
}
</script>
</html>