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