Answer to Question #186799 in C++ for ayush singh

Question #186799

Write a program to count the palindromic array elements from the group of 30 array elements where array is allocated memory dynamically.


1
Expert's answer
2021-04-28T15:49:35-0400
#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;
}

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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS