Palindrome Word

Algorithm

Step 1: Start

Step 2: Declare variables for original string, reversed string, length, and loop index

Step 3: Input the word from the user

Step 4: Find the length of the word

Step 5: Reverse the word and store it in another string

Step 6: Compare the original and reversed string

Step 7: If they match, print palindrome; otherwise, not palindrome

Step 8: End

Flowchart

graph TD; A([Start]) --> B[Declare variables]; B --> C[/Input word/]; C --> D[Find length of the word]; D --> E[Reverse the word]; E --> F[Compare original and reversed]; F --> G{Are they equal?}; G -->|Yes| H[Print Palindrome]; G -->|No| I[Print Not Palindrome]; H --> J([End]); I --> J; classDef start fill:#00cc44,stroke:#006622,stroke-width:2px,color:#ffffff; classDef stop fill:#ff4444,stroke:#cc0000,stroke-width:2px,color:#ffffff; classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000; classDef process fill:#4488ff,stroke:#0044cc,stroke-width:2px,color:#ffffff; classDef decision fill:#ff8844,stroke:#cc4400,stroke-width:2px,color:#ffffff; class A start; class J stop; class C,H,I input_output; class B,D,E,F process; class G decision;

Program

#include <stdio.h>
#include <string.h>

int main() {
    char str[100], rev[100];
    int length, i, isPalindrome = 1;

    printf("Enter a word: ");
    scanf("%s", str);

    length = strlen(str);

    // Reverse the string
    for (i = 0; i < length; i++) {
        rev[i] = str[length - i - 1];
    }
    rev[length] = '\0'; // Null-terminate the reversed string

    // Compare original and reversed string
    for (i = 0; i < length; i++) {
        if (str[i] != rev[i]) {
            isPalindrome = 0;
            break;
        }
    }

    if (isPalindrome) {
        printf("'%s' is a Palindrome.\n", str);
    } else {
        printf("'%s' is NOT a Palindrome.\n", str);
    }

    return 0;
}

Test Case Output
Enter a word: radar
'radar' is a Palindrome.

Enter a word: hello
'hello' is NOT a Palindrome.