0% found this document useful (0 votes)
49 views

Input: A Line Output: Whether The Input Is Palindrome or Not

A recursive function is_palindrome returns true if a line is a palindrome by comparing the first and last characters, recursively calling itself on the substring between them if they match, and false otherwise. A main method gets user input, cleans it keeping only letters and numbers, converts to lowercase, and calls is_palindrome to check if it is a palindrome and print the result.

Uploaded by

assd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Input: A Line Output: Whether The Input Is Palindrome or Not

A recursive function is_palindrome returns true if a line is a palindrome by comparing the first and last characters, recursively calling itself on the substring between them if they match, and false otherwise. A main method gets user input, cleans it keeping only letters and numbers, converts to lowercase, and calls is_palindrome to check if it is a palindrome and print the result.

Uploaded by

assd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a code for the following scenario:

Input: a line
Output: whether the input is palindrome or not
The code should contain
(i) a recursive function is_palindrome that returns true if the input line is a
palindrome and returns false otherwise
(ii) a main method to that takes as input from user a line and uses the function
is_palindrome to check if the line is a palindrome or not

Sample Input Sample Output


abccba Palindrome
abc cc cba Palindrome
Abc ac Not palindrome
Sore was I ere I saw Eros Palindrome
A man, a plan, a canal -- Palindrome
Panama
Never a foot too far, even Palindrome
I am Fariha Not palindrome

Hint: to find the correct answer for all the sample input, you need to delete everything from the
input string except letters and numbers (a-zA-Z0-9) and convert the uppercase to lowercase.
Your code is valid only if it compiles properly. No marks for invalid code.

You might also like