Answer to Question #186678 in C++ for Ravi kumar pandey

Question #186678
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-29T18:59:49-0400
#include <iostream>
#include <ctime>
#include <random>
#include <string>
using namespace std;
int main()
{
	string str;
	int* Array = new int[30];
	srand(time(0));
	for (int i = 0; i < 30; i++)
		Array[i] = rand() % 6;
	int count = 0;
	cout << "[";
	for (int i = 0; i < 30 / 2; i++)
	{
		if (Array[i] == Array[29 - i])
		{
			cout << Array[i];
			count++;
			str += to_string(Array[i]);
			continue;
		}
		cout << '.';
		str += '.';
	}
	for (int i = str.size() - 1; i >= 0; i--)
	{
		cout << str[i];
	}
	cout << "]";
	cout << endl << endl;
	cout << "Count the palindromic array elements is: " << count << endl;
	delete[] Array;
	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