Program to determine if the given string is palindrome or not
12a) Without buit-in-Functions
Source Code:
#include<stdio.h>int main()
{
char string[40];
int length=0, flag=1,i;
printf("Enter string:\n");
gets(string);
for(i=0;string[i]!='\0';i++)
{
length++;
}
for(i=0;i< length/2;i++)
{
if( string[i] != string[length-1-i] )
{
flag=0;
break;
}
}
if(flag==1)
{
printf("PALINDROME");
}
else
{
printf("NOT PALINDROME");
}
return 0;
}
Output:
Enter String:
madam
PALINDROME
12b) With buit-in-Functions
Source Code:
#include<stdio.h>
#include<string.h>
void main()
{
char str1[100],str2[100];
printf("enter the string1 :\n");
gets(str1);
str2=strrev(str1);
if(strcmp(str1,str2)==0)
{
printf("Palindrome");
}
else
printf("Not Palindrome:");
}
Output:
Enter String:
madam
Palindrome
No comments:
Post a Comment