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 |
When does ‘on click of button’ event gets triggered in the vbscript language?
how to set one column as primary key in QTP and fetch values accordingly
Write a program to resize an array of 5 elements to 4 elements and display all the elements.
write generic functions for webapplication?like generic function for webedit generic function for webbutton generic function for links
Hi I don't have any idea on VBscript. can any one point me to a good web site to learn VBscript. Regards lina
How to find arry size in qtp vb script
How to make professional test report using vbscript code in UFT, which gives us complete analysis of the test.
0 Answers College School Exams Tests,
Mention what is byref and byval parameters in vbscript?
Mention what is the difference between vbscript and vba?
How to find the font in qtp. Scenario:After entering the username and passwd you will be navigate into the "welcome:Username" page.Now I want to extarct font for this message.
What is the event handling in vbscript?
Which operator can be used to check if two numbers are equal or not in vbscript?