Can anyone help me to modify the below application code such thatmy Web page wil
ID: 3612714 • Letter: C
Question
Can anyone help me to modify the below application code such thatmy Web page will not only display the approximated value of e ^xbut also value of the loop index and the approximated value aftereach loop iteration is performed.<html>
<head><title>Euler’s Number</title>
<script language = "VBScript">
' write function definitions here
Function factorial(n)
If n <= 1 Then
factorial = 1
Else
factorial = n * factorial(n - 1)
End If
End Function
Sub GetNum_OnClick()
x_num = CDbl(InputBox ("Please enter a number."))
temp_x = x_num
result = Euler(x_num)
document.write("e" & "<sup>" & temp_x &"</sup>" & " = " & result)
End Sub
Function Euler(x)
temp = x
sum = 1
For Index = 1 To 20
sum = sum + x / factorial(index)
x = temp * x
Next
Euler = sum
End Function
</script>
</head>
<body>
<font face = "Tahoma">
<h2>This Document Approximates The Value Ofe<sup>x</sup></h2>
<hr>
<input type = "button" name = "GetNum" value ="Approximate">
</body>
</html>
Explanation / Answer
Dear.. <html><head>
<title>Factorial</title>
<scriptlanguage="VBScript">
functionfactorial(n)
{
if((n == 0) || (n == 1))
return1
else
{
result= (n * factorial(n-1) )
returnresult
answer= document.MyForm.answer.value
}
}
</script>
</head>
<body>
<CENTER>Calculate Factorial of a Number Program
</body>
<form name="MyForm">
<CENTER>
<BR>
<BR>
<BR>
<BR>
<P>Enter a positiveinteger <INPUT TYPE=text NAME=n VALUE="" SIZE=5>
andthen press <input type="button" value="THIS BUTTON"onclick="factorial()"> for answer!
<P>Your Answer is<INPUT TYPE=text NAME=answer VALUE="" SIZE=5>
</FORM>
</body>
</html