0
What is wrong with this code? Always the output is "Yes"
//Created by Homayoon Azizi //Declares if an array is palindrome or not #include <iostream> using namespace std; int main() { char A[]="abcdefg";//length=7 int z,c=0,d=0; for(int i=0;A[i]!='\0';i++)//__i=0~>6 c++;//_____________c=1~>7 z=c;//_____________z=7 c-=1;//____________c=6 for(int i=0;A[i]!='\0';i++){//_i=0~>6 if(A[i]=A[c])//___i=0~>6 c=6~>0 d++;//________d=1~>7 c-=1;}//_______c=5~>0 if(d==z) cout<<"Yes"; else cout<<"No"; return 0" }
2 Answers
+ 3
if you want to check if d and z have the same values, you should use '=='. Otherwise you will overwrite d with z value and see Yes in output anyway
0
@Petr Leliaev
i always write '=' instead of '=='. Anyway i run the code and again same problem,still the output is "Yes"!!