Hi Reader, you may wonder why I’m writing this very old programming technology (Classic ASP) in my blog, the reason behind is, still there are numerous websites running in classic ASP, whereas the new programmers are struggling to work in those websites.
To overcome those issues, I’m writing some simple programs in Classic ASP which may help you to understand how the Classic ASP works.
This blog post is about how to write a Classic ASP program to find factorial, you will learn these,
1. How to check form submission in Classic ASP
2. How to get value from a form input in Classic ASP
3. If statement in Classic ASP
4. For Loop in Classic ASP
5. Multiply in Classic ASP
6. How to print output in Classic ASP
Here is the entire code (Classic ASP Factorial Program):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<html> <body> <title>Factorial Program in Classic ASP</title> <!-- form post method --> <form action="" method="post"> <label>Enter a Number to calculate Factorial</label> <input type="text" name="number" size="2" /> <input type="submit" value="Find" name="submit" /> </form> </body> </html> <% 'check for form submission and then allow If Request.ServerVariables("REQUEST_METHOD") = "POST" Then fact = 1 'get the value from input text box 'number' number = Request.form("number") Response.Write("Factorial of "+number+"<br><br>") For i = 1 to number 'formula to calculate factorial is to 'multiply the iterator i value with fact value. fact = fact * i 'print fact to show the factorial pyramid 'or put this line out of this 'for loop' to show only the total value Response.Write(fact) Response.Write("<br>") Next end if %> |
Read the comments in the above code to understand it.