Pages

Find Factorial using While loop


Module PerNum_inBetween
    Sub main()
        Dim min, max, p, sum, r AModule Factorial

    Sub Main()
        Dim n, fact, t As Integer
        Console.Write("Enter a Number:")
        n = CInt(Console.ReadLine())
        Console.WriteLine("Given Number= " + n.ToString())
        t = n
        fact = 1
        If t < 0 Then
            Console.WriteLine("No factorial for negative number")
        ElseIf t = 0 Or t = 1 Then
            Console.WriteLine("Factorial of " + t.ToString() + "is 1")
        Else

            While t > 0
                fact *= t
                t -= 1
            End While
            Console.WriteLine("Factorial of " + n.ToString() + "=" + fact.ToString())

        End If
        Console.ReadLine()

    End Sub

End Module

No comments:

Post a Comment