Skip to main content
BSC Moodle
Log in
  • Moodle Home
  • MyBSC Links
    Academic Alerts (formerly Starfish) Apogee BSC Email BSC Intranet BSC Website Change Password Colleague Events Records IT Helpdesk IT Help for Online Course Students Library MobilePrint OrgSync TheSIS Time & Attendance Trakstar
  • Moodle FAQs
  1. Home
  2. Courses
  3. Miscellaneous
  4. 22FA_CAC180A
  5. Week Eleven: 10/31-11/4
  6. Lab #10: Recursion

22FA_CAC180A-Programming

Lab #10: Recursion

Completion requirements
Make a submission
Opened: Monday, 27 April 2020, 12:00 AM
Due: Friday, 4 November 2022, 11:59 PM

Please write recursive solutions to the following problems (choose two): 

1. Palindrome: Write a recursive function that determines whether or not a string is a palindrome. The empty string is a palindrome, as is any string containing only one character. Any longer string is a palindrome if its first and last characters match, and if the string formed by removing the first and last characters is also a palindrome.

Write a main method that reads a string from the user. Use your recursive function to determine whether or not the string is a palindrome. Then display an appropriate message for the user.

2. Fibonacci: Write a recursive function that computes the nth number in the Fibonacci sequence. The Fibonacci sequence starts with two 1's. 1, 1, and the remaining numbers are the result of adding the two previous numbers. 1,1,2,3,5,8,13,21...

Write a main method that asks the user to enter the number of the sequence to compute. Use your function to compute that number in the sequence (for example, if the user entered 6, your function would return 8 because that is the 6th number in the sequence), and display the result with an appropriate message. 

3. Factorial: Write a recursive function to compute the factorial of a number. The factorial of a number is that number times itself -1 until you get to 1. For example: 

1! = 1

2! = 2 * 1! = 2 * 1 = 2

3! = 3 * 2! = 3 * 2 * 1! = 3 * 2 * 1 = 6

4! = 4 * 3! = 4 * 3 * 2! = 4 * 3 * 2 * 1! = 4 * 3 * 2 * 1 = 12

Write a main method that allows the user to enter a number. Use your function to compute the factorial of that number and display the result with an appropriate message. 

◄ Participation: Towers of Hanoi Worksheet
Lecture: Introduction to Classes ►

Moodle Help

BSC Students - Please contact the BSC Helpdesk at helpdesk@bsc.edu or 205-226-3033, option 2. If you're an online course student, please consult the IT Website for Online Course Students. 

BSC Faculty and Staff - Please visit the Instructional Technology Moodle Course or contact Angela Brooks at adbrooks@bsc.edu, 205-226-3039.

facebooklinkedininstagram

  • Moodle Home
  • MyBSC Links
    Academic Alerts (formerly Starfish) Apogee BSC Email BSC Intranet BSC Website Change Password Colleague Events Records IT Helpdesk IT Help for Online Course Students Library MobilePrint OrgSync TheSIS Time & Attendance Trakstar
  • Moodle FAQs
Built with Open LMS, a Moodle-based product.
Copyright © 2024 Open LMS, All Rights Reserved.

Data retention summary
Get the mobile app
Switch to the standard theme