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
#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;
}
Comments
Leave a comment