Site icon TestingDocs.com

Flowchart to print n natural numbers in reverse order

Overview

In this tutorial, we will create a RAPTOR flowchart to print n natural numbers in reverse order. The flowchart would prompt the user to enter the number. The flowchart uses a recursive procedure to print the numbers in reverse order.

Recursive procedure

A recursive procedure call is a procedure call that calls the procedure itself.  In this example, the main flowchart prompts the user for the number. The main then invokes the procedure print. The print()  procedure is recursive.

main invokes print with -> print(n)

print() invokes -> print(n-1)

To know more on the RAPTOR procedure, follow the link:

https://www.testingdocs.com/procedure-in-raptor-flowcharts/

Flowchart

 

Base Case

When we work with recursive procedures we need to take care of two things. Base case and convergence of the problem that is being solved.

The base case is the halting case. We need to stop the recursion, otherwise, there is a risk of infinite recursion and unwanted errors in the flowchart. Infinite recursion is a recursion that doesn’t end without any halting case.  In the example, the recursion stops when n == 0. We can see the call stack of the recursion in the left activity window.

Convergence is another requirement for the recursive function or procedure. We need to converge the problem that we solve using recursion. In this example, the next recursive call converges the problem by calling the smaller n i.e n-1 , n-2 , n-3 etc with the base n==0.

Sample Output

Let’s run the flowchart with sample test cases to verify that it’s working as intended. If you find that the flowchart is not working as intended in the testing, we may need to verify and debug the flowchart.

Debugging a flowchart: https://www.testingdocs.com/debugging-a-raptor-flowchart/

Output

Enter number : 5

5   4   3   2   1

 

Raptor Tutorials on this website can be found at:

https://www.testingdocs.com/raptor-a-flowchart-tool/

RAPTOR official website: https://raptor.martincarlisle.com/

Exit mobile version