Question

PLEASE USE MATLAB

This is a basic problem that illustrates the concept of strings. A palidrome is a string of characters that is read the same

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation :

We will take string from user and will go through each character of first half of string and will compare it with its mirror counter part. If there is any mismatch, we will return the false or 0 otherwise true or 1.

Code:

function isPal = isPalindrome(str)
%initiating the function

n = length(str);
%Finding length of string

isPal = true;
%initiating the answer as true or 1;

ii = 1;
%initiating the index as 1

while ii<=floor(n/2)
%to go through only first half of the string

if str(ii)~= str(n-ii+1);
%Comparing the mirror images
  
isPal = false;
%Changing the answer if the condition is satisfied
  
return
%Getting out of loop if condition is satisfied
  
end
  
ii = ii+1;
%Increasing the index after evry loop to consider next char
end

end

Output as requested :

Command Window >isPalindrome racecar) ans 1 >isPalindrome (Racecar) ans >isPalindrome (dad) ans 1 > isPalindrome (gogg

Add a comment
Know the answer?
Add Answer to:
PLEASE USE MATLAB This is a basic problem that illustrates the concept of strings. A palidrome...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...

    Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc. Your task is to write a function ispalindrome(string) that reads an input string and returns True if both of the following are true: The string is a palindrome The string has at least one letter (uppercase or lowercase) For example: ispalindrome('racecar') should return True PS: ispalindrome('123321') should return False ispalindrome('racecar') should return True

  • For this assignment, you will create a program that tests a string to see if it...

    For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...

  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...

    C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work. Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...

  • Please write in java Write a main program that runs the following two recursive methods demonstrating...

    Please write in java Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...

  • [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples...

    [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc Your task is to write a program that reads an input string prints that string, and then prints one of the following as appropriate: Is a Palindrome or Nota Palindrome I user response is input - racecar, the above program should print гacecar Is a Palindrome If user response is input = hello, the above program should print...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include...

    Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT