+ 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; }

17th Jul 2020, 3:21 AM
Abhishek Kumar
Abhishek Kumar - avatar
1 Antwort