Challenge: Palindrome Check
Completed
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
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
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module