write a program to count the palindromic array element from the group of 30 array element where arrays is allocated memory dynamically . program c++
Answers
Answered by
1
Answer:
#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;
}
Similar questions
Computer Science,
18 days ago
English,
18 days ago
Math,
1 month ago
English,
8 months ago
English,
8 months ago