|
Julia is a dynamic, high-level programming language with high performance and speed that is used to perform operations in scientific computing. It is great for computational complex problems. It is an open-source language so all source code is available easily online. It is as easy to use as Python but it has much faster execution compared to R and Python. Julia is a general-purpose language and can be used for various tasks such as statistical computations, data analysis, web development, game development and more. Ways to run Julia:
As Julia is a lot similar to other mostly used languages syntactically, it is easier to code and learn Julia. Julia programs are to be saved in a file with .jl extension. Simple Julia Program: Simple program to print Hello Geeks, just type the following code after the start of the interpreter. Julia
Before we see Recursion in Julia, we need to know what actually recursion is. What is Recursion?It is a process in which a function calls itself either directly or indirectly. It is a technique that helps us to solve complex problems easily with elegant code. Classical problems of recursion include the Towers of Hanoi. The idea of recursion is to represent a problem in terms of smaller problems, and add some conditions to stop it at some base levels. Mathematical Interpretation An object possesses recursive behaviour if it can be defined by the following properties:
Julia – Recursion Let us see how recursion works in Julia language with the help of examples. Example 1: In this example, we are finding the multiplication of two numbers. Say num1*num2. It is the same as adding num1 to itself repeated num2 times. For example – 5*4 is the same as 5+5+5+5. We will code this problem in both ways iterative and recursive. Iterative Code: Julia
Output: Recursive Code: Julia
Output: Example 2: In this example, we are finding the factorial of a number. n!=n*(n-1)*(n-2) . . . . *1. Let’s say the number is 5. 5!= 5*4*3*2*1=120. In Julia factorial can be found out in three ways – using the built-in factorial function, another way is the iterative way and the third one is the recursive way. Using Built-In function- Julia
Output: Iterative Code- Julia
Output – Recursive Code- Julia
Output- |
Reffered: https://www.geeksforgeeks.org
Julia |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |