C++
1. An array of integers is said to be a palindrome if it is read the same from right to left and from left to right such as 1 2 3 2 1. Implement a program that: a. Prompts the user for an integer value n which represents the number of integers to be read next. b. Create a one dimensional dynamic array with size equal to n. c. Create two pointers front and rear and make them point to the 1st and last elements in the array. Print out an appropriate message if the array is a palindrome or not.
ANSWER:-
#include <iostream>
using namespace std;
int main() {
int n,flag=0;
cout<<"enter the size of the array : ";
cin>>n;
int arr[n];
cout<<"enter the numbers : ";
for(int i=0;i<n;i++)
cin>>arr[i];
int *front,*rear;
front=arr;
rear=arr+n-1;
for (int i = 0; i <= n / 2 && n != 0; i++)
{
if (*front != *rear) {
flag = 1;
break;
}
front++;
rear--;
}
if (flag == 0)
cout << "Palindrome\n";
else
cout << "Not Palindrome\n";
return 0;
}
OUTPUT:-
// If any doubt please comment
Get Answers For Free
Most questions answered within 1 hours.