write a vb script to calculate factorial of a number?
Answers were Sorted based on User's Feedback
Answer / mudaseer
vf=1
vnum=inputbox("enter a no")
for i=2 to vnum
vf=vf*i
next
msgbox vf
Is This Answer Correct ? | 98 Yes | 25 No |
Answer / raja
Dim n,f
n=inputbox("enter a number")
f=1
If n<0 Then
msgbox "invalid number"
else if n=0 or n=1 then
msgbox "the factorial of given number is : "& f
else
For i=1 to n
f=f*i
Next
msgbox "the factorial of given number is : "&f
End If
end if
Is This Answer Correct ? | 77 Yes | 19 No |
Answer / rik mondal
The answer submitted by "mudaseer" is absolutely wrong and
the answer by "raja" is partially correct(because he did not
wrote additional HTML and script tags,which is difficult to
understand for beginners). Guys don't you check the answer
before posting?
anyways here is the correct answer. This will work 100%.
Just copy it and paste in you editor then save and compile
by IE.
<html>
<script language="vbscript">
n=inputbox("Enter a number")
dim f
f=1
if n<0 then
Msgbox "Invalid number"
elseif n=0 or n=1 then
MsgBox "The factorial of given number "&n&" is :"&f
else
for i=n to 2 step -1
f=f*i
next
MsgBox "The factorial of given number "&n&" is :"&f
end if
</script>
</html>
Is This Answer Correct ? | 41 Yes | 16 No |
Answer / arvind singh
a = InputBox("Enter a no to calculate factorial for")
Result = 1
Do While a > 0
Result = Result*(a)
a = a-1
Loop
MsgBox Result
Is This Answer Correct ? | 8 Yes | 4 No |
why do u choose to go for testing why cant for devoloping
How to open a file. What is the perpose of true and false mode there?
Give examples where vb script can directly run on users system with windows as os?
What is variant in vb script?
In html file what is an ideal position to include vbscript?
Write a Program to add 2 numbers without using operators (+,-) and without using third variable. Note: Use VBScript only Hint: You can use other operators like '/' & '*'(Division & Multiplication)
which one is more secure vb script or java script ??????? or both are same ??????
Is vbscript a case-sensitive or case-insensitive?
Write a program to print all lines that contains a word either “testing” or “qtp”
how to write vb script code for login gmail page by using notepad and how to run script in notepad
Why do we use Option Explicit?
Hi this is Vinoth. I need a help on below mentioned question A combobox contains list of items assume as 5 I have to get each items Individually and I have to Export to datatable. Please help me on this. Thanks