Write in C language Description Write a program to determine if a string is apalindrome or not. Input Input string will include only letter,please consider uppercase and lowercase as the same. Output Please refer to the sample output. Sample Input 1  AbcBa Sample Output 1 AbcBa is a palindrome. Sample Input 2  AAaab Sample Output 2 AAaab is not a palindrome.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
100%

Write in C language

Description

Write a program to determine if a string is apalindrome or not.

Input

Input string will include only letter,please consider uppercase and lowercase as the same.

Output

Please refer to the sample output.

Sample Input 1 

AbcBa

Sample Output 1

AbcBa is a palindrome.

Sample Input 2 

AAaab

Sample Output 2

AAaab is not a palindrome.

Expert Answer (Output doesn't match Sample output)

Step 1

#include <stdio.h>
#include <string.h>
int main(){
    char string1[20];
    int i, length;
    int flag = 0;
    printf("Enter a string:");
    scanf("%s", string1);
    length = strlen(string1);
    for(i=0;i < length ;i++){
        if(string1[i] != string1[length-i-1]){
            flag = 1;
            break;
   }
}
    if (flag) {
        printf("%s is not a palindrome", string1);
    }    
    else {
        printf("%s is a palindrome", string1);
    }
    return 0;
}

Step 2

OUTPUT

Enter a string : Wow

Wow is a palindrome (saying not a palindrome)

Press any key to continue

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT