Question

Write a C Program that asks the user to input a string and then the user...

Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.)

Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not.

Use Pointers to traverse the string.

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

#include<stdio.h>

#include<string.h>

#include<stdbool.h>

bool isPalindrome(char str[])

{

    // point to the starting character

    char *start = str;

   

    // point to the ending character

    char *end = str + ( strlen(str) - 1 );

   

    // loop untill start pointer is before end pointer

    while( start < end )

    {

        // if the current character from start and end are not equal

        if( *start != *end )

            return false;

           

        // update the pointers

        start++;

        end--;

    }

   

    return true;

}

int main()

{

    char str[100];

   

    printf("Enter a string : ");

   

    // read complete line

    gets(str);

   

    // if it is palindrome

    if( isPalindrome(str) )

        printf("it is palindrome.");

    // if it is not palindrome

    else

        printf("it is not palindrome.");

   

    return 0;

}


Sample Output

it is palindrome

Add a comment
Know the answer?
Add Answer to:
Write a C Program that asks the user to input a string and then the user...
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
  • 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...

  • palindrome is a string that reads the same both forward and backward. C++ For example, the...

    palindrome is a string that reads the same both forward and backward. C++ For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

  • Complete the printPalindrome method in the provided Palindrome.java program. The printPalindrome method accepts a String as...

    Complete the printPalindrome method in the provided Palindrome.java program. The printPalindrome method accepts a String as a parameter and prints whether the parameter String is a palindrome (i.e., reads the same forwards as it does backwards, for example, "abba" or "racecar"). Make the code case-insensitive, so that words like "Abba" and "Madam" will be considered palindromes. import java.util.*; /** * Determines if a user entered String is a palindrome, which means the String * is the same forward and reverse....

  • C language: Write a program that uses a function to check if a user entered string...

    C language: Write a program that uses a function to check if a user entered string is a palindrome. Based on the return value of the function, the results are printed in the main() function. (do not print results in function to check for palindrome) A palindrome reads the same forward as backward for example tacocat or civic.

  • A palindrome is a word, phrase, number, or other sequence of characters which reads the same...

    A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion {                 public static void main(String[] args) {                                 Recursion r = new Recursion();                                 System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true                 }                 public Boolean isPalindrome(int num){                                 return false;...

  • C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string cl...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • In C++ Write a program that: Gets a string from cin Prints TRUE if the string...

    In C++ Write a program that: Gets a string from cin Prints TRUE if the string is a palindrome, FALSE otherwise, all uppercase, followed by endl. Palindrome reads the same backward as forward, e.g., madam.

  • C++ A palindrome is a string that reads the same backward as forward. For example, the...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • Exercise 1 Write a recursive method to check if a string is palindrome. public static boolean...

    Exercise 1 Write a recursive method to check if a string is palindrome. public static boolean isPalindrome(String s) { A Palindrome String is string which reads the same backward as forward, such as madam or racecar

  • Develop a C++ program that reads a paragraph of text from a file. Tokenizes it such...

    Develop a C++ program that reads a paragraph of text from a file. Tokenizes it such that each token is a word, determines whether a token is a palindrome (that is a word that reads the same forward and backward such as ‘madam’ or ‘1991’). Prints all palindrome and the total number of palindrome.Your source code shall consists at least three function apart from main(). Shows a program structure chart,flowchart,source code & output.

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