Write a program to count the palindromic array elements from the group of 30 array elements where array is allocated memory dynamically.
#include <iostream>
#include <random>
using namespace std;
int main()
{
int* A = new int[30];
srand(10);
for (int i = 0; i < 30; i++)
{
A[i] = rand() % 5;
}
int count = 0;
for (int i = 0; i < 30 / 2; i++)
{
if (A[i] == A[29 - i])
{
cout << count + 1 << " palindromic elements in array: " << A[i] << ". Position: " << i << " and " << 29-i << endl;
count++;
}
}
cout << endl;
cout << "Total count of palindromic array elements is: " << count << endl;
delete[] A;
return 0;
}
Comments
Leave a comment