In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
Code Screenshot :
Executable Code:
recursive.myprint<-function (x) {
#Quit if number less than or equal to 1
if (x <= 1)
quit()
#Print the numbers
print(x - 1)
#Recursive call to the function
recursive.myprint(x - 1)
}
#Function Call
recursive.myprint(5)
Sample Output:
Please comment
below if you have any queries.
Please do give a thumbs up if you liked the answer thanks
:)
Get Answers For Free
Most questions answered within 1 hours.