Question

41. (10 points) EXTRA CREDIT: Write a function palindrome to determine if an input string s is a palindrome. Let the empty
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
   cout<<"Enter a string:-";
   string a;
   cin>>a;
   for(int i=0;i<a.length()/2;i++){
       if(a[i]!=a[a.length()-i-1]){
           cout<<"Not a palindrome\n";
           return 0;
       }
   }
   cout<<a<<" is a Palindrome\n";

  
}

Enter a string:-ABa Not a palindrome Enter a string:-aaaa aaaa is a PalindromeEnter a string:-tat tat is a Palindrome1 #include <bits/stdc++.h> #include<cmath> using namespace std 3 Eint main 4 cout<<Enter a string string a 7 cin>>a; for (i

Add a comment
Know the answer?
Add Answer to:
41. (10 points) EXTRA CREDIT: Write a function 'palindrome' to determine if an input string s...
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
  • Write a recursive function, take a String as input, return true, if the String is a...

    Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • C Program: Write the following function that takes a user input string, computes, and determines whether the input is palindromic or not by returning either true or false:

    A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads the same forward or reversed. Examples: “Dad”, “Anna”, “Never odd or even”, etc. For this problem, we will only consider a string to be palindromic if its combined alpha-numeric characters (‘A’-’Z’, ‘a’-’z’, and ‘0’-’9’) can be read the same both forward and backward, by skipping all other non-alphanumeric characters.Write the following function that takes a user input string, computes, and determines whether the input is palindromic or not...

  • sorted vowels Write a function that returns true if the vowels in the input string A...

    sorted vowels Write a function that returns true if the vowels in the input string A appear in non-decreasing order and false otherwise. You can assume this function is not case sensitive. If the string does not contain any vowels, it must return true. bool sorted_vowels (const char A)

  • Palindrome is a word or a phrase when taken in reverse order, gives the same word...

    Palindrome is a word or a phrase when taken in reverse order, gives the same word or phrase. For example, the word “radar” is a palindrome. The phrase "Do geese see God?" is also a palindrome after the removal of the question mark and all the spaces and the conversion of the remaining alphabets to either upper or lower case. Write a program that uses an STL stack to check if an arbitrary string containing multiple words separated by spaces...

  • Write a function is_mirror(s) that takes as input a string s and returns True if s...

    Write a function is_mirror(s) that takes as input a string s and returns True if s is a mirrored string (i.e., a string that could have been produced by your mirror function) and False otherwise. Examples: >>> is_mirror('baconnocab') result: True >>> is_mirror('baconnoca') result: False Warning Your function should return a boolean value – either True or False, without any quotes around them. If you see quotes around the result when you make the calls above from the console, you must...

  • PLEASE USE MATLAB This is a basic problem that illustrates the concept of strings. A palidrome...

    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 forwards as it is backwards. For example, racecar' is a palindrome; reversing the order of the characters leaves the string unchanged. Write a otherwise. function called isPalindrome that accepts one input and returns one output. The input str is a string of characters, and the output is 1 if str is a palindrome, For...

  • Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of...

    Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of text file to write to Outputs: none File Outputs: 1. A text file containing all the permutations of the anagram Banned Functions: perms(), permute(), ipermute(), nchoosek (), combnk() Background: You guys know what do. You are professional MATLAB now, you got this! Function Description: Given a string, recursively determine all the unique ways to rearrange the letters. (i.e al the unique permutations). For example,...

  • Write the function in python and show the code 2. Write a function jscore (s1, s2)...

    Write the function in python and show the code 2. Write a function jscore (s1, s2) that takes two strings s1 and s2 as inputs and returns the Jotto score of s1 compared with s2 -.e., the number of characters in s1 that are shared by s2. The positions and the order of the shared characters within each string do not matter. Repeated letters are counted multiple times, as long as they appear multiple times in both strings. For example...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

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