Answer to Question #276256 in C++ for zain

Question #276256

1.   Programming Problem I ( class, stack, array )

Given an array based stack of size N containing integers, tell whether it is a palindrome or not.

 

For example

Input:                    N=3

Value [ ]={1,2,1}

Output:                 1


1
Expert's answer
2021-12-08T19:03:59-0500
#include <iostream>
using namespace std;
 
void palindrome_checker(int array[], int size)
{
   
    int f = 0;
 
    
    for (int x = 0; x <= size / 2 && size != 0; x++) {
 
        
        if (array[x] != array[size - x - 1]) {
            f = 1;
            break;
        }
    }
 
   
    if (f == 0)
        cout << 1;
    else
        cout << 0;
}
 


int main()
{
    int array[] = {1,2,1};
    int size = sizeof(array) / sizeof(array[0]);
 
    palindrome_checker(array, size);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment