-3
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int arr[30];
    bool palindrome=true;
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    for(int i=0; i<n/2; i++){
        if(arr[i]=!arr[n-1-i]){
            palindrome=false;
            break;
        }
    }
    if(palindrome==true){
        cout<<"Symmetric";
    }else{
        cout<<"Not symmetric";
    }
    return 0;
}

whats wrong with above code? its showing not symmetric in every input.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
D4MONz
  • 1
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to [edit] your question to improve it, like removing dummy filler text and instead tell us the expected and actual behavior etc. – Some programmer dude Aug 01 '22 at 19:14
  • This also seems like a very good time to learn how to [*debug*](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) your programs. For example how to use a [*debugger*](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) to step through your code statement by statement while monitoring variables and their values. – Some programmer dude Aug 01 '22 at 19:15
  • dont ignore compiler warnings https://godbolt.org/z/crWMWP3cr – 463035818_is_not_an_ai Aug 01 '22 at 19:16
  • Also take this as a lesson to build with multiple compilers and add extra warnings when building. [Two of the big three compilers will be able to detect the problem](https://godbolt.org/z/jbhM6YP5Y). – Some programmer dude Aug 01 '22 at 19:19
  • Unrelated, `if(palindrome==true)` is superfluous. `if(palindrome)` ftw. – WhozCraig Aug 01 '22 at 19:21

1 Answers1

1

if(arr[i]=!arr[n-1-i]){

you likely wanted to write

if(arr[i]!=arr[n-1-i]){

lorro
  • 10,687
  • 23
  • 36