Program to check whether a number is palindrome or not in C

Source Code

// 24. Program to check whether a number is palindrome or not
// Arpan Das - CST 2nd Year (VOCLET)

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


int main() {
	int i, j, flag=1, len;
	char word[30];
	//clrscr();

	printf("Please enter any word: ");
	//gets(word);
	scanf("%s", word);
	len = strlen(word);

	// india -> 5
	for (i=0, j=len-1; i<j; i++, j--) {
		if (word[i] != word[j]) {
			flag = 0;
			break;
		}
	}

	if(flag == 1)
		printf("\n%s is palindrome", word);
	else
		printf("\n%s is not palindrome", word);

	//getch();
}

Output

Please enter any word: INDIA

INDIA is not palindrome


Please enter any word: MOM

MOM is palindrome

Leave a Reply

Note: Your email address will not be published. Required fields are marked *