Answer to Question #160015 in Visual Basic for sidd

Question #160015

Write Algorithm and Flowchart to implement a program to accept a number in a Textbox and display the result of Factorial of that number in another TextBox.




1
Expert's answer
2021-01-31T11:01:18-0500
Algorithm 

Start
       Declare the variable number
       Declare the variable factorial =1
       If number < 0 Then
            Display the message: "Factorial of negative number is not possible"
       ElseIf number = 0 Or number = 1 Then
            factorial=1
            Display the factorial
       Else
            Calculate the factorial using for loop
            For i = 1 To number
                factorial = factorial * i
            Display the factorial
       End If
Stop

Visual Basic Code:


Public Class frmFactorialNumber
    ''' <summary>
    ''' Calculate button
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        'Declare variable number
        Dim number As Integer
        'Declare variable factorial
        Dim factorial As Integer = 1
        'check if number is correct
        If Integer.TryParse(txtNumber.Text, number) = False Or number < 0 Then
            'Display the message: "Factorial of negative number is not possible"
            MessageBox.Show("Factorial of negative number is not possible")
        ElseIf number = 0 Or number = 1 Then
            'Display the factorial
            txtFactorial.Text = factorial.ToString()
        Else
            'Calculate the factorial using for loop
            For i = 1 To number
                factorial = factorial * i
            Next
            'Display the factorial
            txtFactorial.Text = factorial.ToString()
        End If
    End Sub
End Class

Flowchart 


Example:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS