49. JavaScript Program to Compute the 1.0+1.1+1.2+1.3 + …… + 2.5 Series.
How does this program work?
- This program is used to find the Sum of the given series 1.0+1.1+1.2+1.3 + …… + 2.5 using JavaScript.
- Declare variables sum and Initially initialize with 1.
- By using for loop we can find the sum of given series upto nth term.
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 number"> </td>
</tr>
<tr>
<td> <button onclick="series7 ()" >Submit</button> </td>
</tr>
</table>
<div id="num"></div>
</body>
<script type="text/javascript">
function series7()
{
var sum, i;
sum = 0;
var n = document.getElementById ('first').value;
for(i = 1.0; i <= n; i+=0.1)
{
sum = sum+i;
}
document.getElementById ('num').innerHTML = "Sum of the given series : "+ sum;
}
</script>
</html>