Answer the question
In order to leave comments, you need to log in
How to fill array arr[n][n] with random numbers, N value is entered through TextBox component?
Good day!
It is necessary to fill the array a[n][n] with random numbers in the range [-50; fifty]. The N value is entered through the TextBox component Display the elements of the main diagonal of the array (dataGrigView) in ascending order.
I'm stuck on the fact that I can't populate an array:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int n1 = Convert::ToInt32(textBox1->Text);
int n2 = Convert::ToInt32(textBox2->Text);
int arr[n1][n2]; //ошибка выражение должно иметь константное значение!
for (int i = 0; i <= n1; i++) {
for (int j = 0; j <= n2; j++) {
arr[i][j] = rand() % 50 -50;
}
}
}
Answer the question
In order to leave comments, you need to log in
Use the new (gcnew) operator to declare a dynamic array. Or use a std::vector container.
Here is a well-written what's what
https://stackoverflow.com/questions/9219712/c-arra...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question