+ 1
Is this code right for palindrome in string
#include <iostream> #include<string.h> using namespace std; int main () { char str[50], flag; int i, j; cout << "Enter a string : "; cin>>str; cout<<str<<endl; j = strlen(str)- 1; for (i = 0; i < j; i++,j--) { if(str[i++]==str[i--]) flag=1; } if(flag) cout<<"palindrome"; else cout<<"not palindrome"; return 0; }
1 Answer