1. to determine if a string is a palindrome:
/*
determines if a string is a palindrome
*/
#include
int isPalindrome(char string[],int length);
main()
{
int length;
char text[80];
printf("please enter the text:");
gets(text);
length=strlen(text);
if(isPalindrome(text, length))
printf("yes it is a palindrome.\n");
else
printf("sorry its not a palindrome.\n");
return EXIT_SUCCESS;
}
int isPalindrome(char string[], int length)
{
int ctr=length-1;
int i;
int value=0;
for(i=0;i<=ctr/2;i++)
{
if(string[i] != string[ctr])
break;
else value=1;
}
return value;
}
obviously the teacher will doubt if the code if its really yours when they saw the statement return EXIT_SUCCESS so if your a beginner just like me try something else so that your teacher wont bother you. :)

No comments:
Post a Comment