Tuesday, 25 February 2014

Palindrome in c without using string function

Palindrome in c without using string function
#include<stdio.h>
int main(){
  char str[100];
  int i=0,j=-1,flag=0;
  printf("Enter a string: ");
  scanf("%s",str);
  while(str[++j]!='\0');
  j--;
  while(i<j)
      if(str[i++] != str[j--]){
           flag=1;
           break;
      }
    
  if(flag == 0)
      printf("The string is a palindrome");
  else
      printf("The string is not a palindrome");
  return 0;
}

No comments:

Post a Comment