Challenge: Palindrome Check

Lab C Intermediate 20 points

Read one word (only small letters) and print yes if it reads the same backwards (like level), otherwise no.

Input

One word.

Output

yes or no.

Example

Input

level

Output

yes
Sample input available Sample output available
Editor
C

Hints

Compare the first and last letters, then move inwards.

Stop as soon as two letters differ.

Solution explanation

Two positions walk towards the middle. If every pair matches, the word is a palindrome.

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

int main() {
    char word[101];
    scanf("%s", word);
    int left = 0;
    int right = strlen(word) - 1;
    int same = 1;
    while (left < right) {
        if (word[left] != word[right]) {
            same = 0;
            break;
        }
        left++;
        right--;
    }
    if (same) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD