Program to find the factorial of a number using foreach loop in VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 1060
Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication1
Class Program
Private Shared Sub Main(args As String())
Dim input As Integer = 10
'Factorial of the number to find
Dim fact As Integer = 1
'a temporary variable to store the intermediate computed values
'the computation
For Each number As var In Enumerable.Range(1, input).ToList()
fact *= number
Next

'display the result
Console.WriteLine("Factorial of {0} is {1}", input, fact)
Console.ReadKey()
End Sub
End Class
End Namespace


Output
-------------
Factorial of 10 is 3628800

Comments or Responses

Login to post response