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 |
Hi everybady, i have faced few Qns in one of i attended interview, please help me out with these below Qns. 1. how to join values without using join function? 2. how to compare values without using String compare function? 3. input is Bangalore, but i need output like this below format, what is function to use and get this outcome B A N G A L o R E 4. Input is "CapGemini" but uotput should be like this "inimeGpaC" 5. Input is 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Can someone let me know results of this Qns, please. Thanks.
input values to accept 2 numbers & print the product, difference and sum using switch case
How to open browser in vb script?
Explain about .wsf files?
What is the use of "Option Explicit"?
i want to when we will write the scripts either after getting the build or after getting the SRS?
Hellow friends, I am learning QTP,but here problem is VB script. please guide me how to learn VB script w.r.t QTP and if you know any books tell me or if you have any materials or any use full material or any else w.r.t QTP please post me p.p.sekhar
Explain the filter expression?
How to pass argument by reference to a function in vbscript?
write a vb script code to display the vbscript word by word (i e 1st it should display v then b and up to t )
how to find greatest of n numbers!
Explain a few date functions in vbscript