Answer to Question #335385 in C++ for Array 3

Question #335385

Input a random positive integer, n.



Create an empty character array with a size of the inputted random positive integer, n.



In the next succeeding lines, store the n characters into the character array.



Input an integer, m, for an index. This value should be from 0 to n - 1.



Using your understanding on accessing array elements, access and print out the array element having the index position of the inputted random integer, m.

1
Expert's answer
2022-04-29T11:29:32-0400
#include <iostream>

using namespace std;

int main()
{
	int n;
	cout << "Please, enter a size of character array: ";
	cin >> n;
	char* arr = new char[n];
	cout << "Please, enter characters: ";
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int m;
	cout << "Please, enter an integer value between 0 to n-1: ";
	cin >> m;
	if (m < 0 || m > n - 1)
		cout << "Incorrect value!";
	else
		cout << "Value arr[m] = " << arr[m];
}

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