Programming In C Practical 21

Question 1
Checking palindrome using string function
Palindrom.cpp
C
				#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
	clrscr();
	char str[30];
	int i=0,flag=0,len;
	printf("\nEnter a string: ");
	scanf("%s",str);
	len=strlen(str);
	len--;
	while(i<=len)
	{
		if(str[i]!=str[len])
		{
			flag=1;
			break;
		}
		i++;
		len--;
	}
	
	if(flag==1)
		printf("\nString is not palindrom");
	else
		printf("\nString is palindrom");
	
	getch();
}
			
Output

Leave a Comment

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