ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the recursive function

Here, we are going to demonstrate the recursive function in VB.Net.
Submitted by Nidhi, on December 14, 2020

Here, we will create a recursive function Recursive() that will print numbers from 5 to 1 on the console screen.

Program/Source Code:

The source code to demonstrate the recursive function is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the recursive function.

Module Module1

    Function Recursive(ByVal count As Integer) As Integer
        Console.Write("{0} ", count)
        count = count - 1

        If (count = 0) Then
            Return count
        End If

        Return Recursive(count)
    End Function

    Sub Main()
        Recursive(5)
        Console.WriteLine()
    End Sub
    
End Module

Output:

5 4 3 2 1
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a user-defined recursive function Recursive() and Main() subroutine.

The Main() subroutine is the entry point for the program. Here, we call the function Recursive() with value 5.

In the Recursive() function, we printed the value of parameter count and decrease the value of variable count by 1 till it becomes 0. In every recursive call value of the count get a decrease and print an updated value on the console screen.

VB.Net User-defined Functions Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.