يرجى الدخول لحسابك أو تسجيل حساب لتستطيع إضافة تعليق
حساب جديد
دخول
التعليقات
المُشكلة في إسناد القيم للمصفوفة سيكون كالتالي:
//// Initialization
age[0, 0, 0] = 100;
age[0, 0, 1] = 200;
age[0, 0, 2] = 300;
age[0, 1, 0] = 400;
age[0, 1, 1] = 500;
age[0, 1, 2] = 600;
راجع المصفوفات الرياضية :)
- بالنسبة لتنسيق الكود ضعه في محرر خارجي وأزحة بمسافة Tab ثم قم بوضعه هنا ولتلاشي أي خطأ أترك سطر فارغ قبل وبعد الكود.
لماذا قمت بتغيير هيكلة حلقات التكرار فكودك في المُشاركة الأولى صحيح وهو:
// Declaration
int[, ,] age = new int[1, 2, 3];
//// Initialization
age[0, 0, 0] = 100;
age[0, 0, 1] = 200;
age[0, 0, 2] = 300;
age[0, 1, 0] = 400;
age[0, 1, 1] = 500;
age[0, 1, 2] = 600;
// Printing the array by using three for loops
for (int i = 0; i < age.GetLength(2); i++)
{
for (int y = 0; y < age.GetLength(1); y++)
{
for (int x = 0; x < age.GetLength(0); x++)
{
Console.Write(age[x, y, i]);
}
Console.WriteLine();
}
Console.WriteLine();
}
لشكل أكثر وضوحاً:
// Declaration int[x, y, z]
int[, ,] age = new int[1, 2, 3];
//// Initialization
age[0, 0, 0] = 100;
age[0, 0, 1] = 200;
age[0, 0, 2] = 300;
age[0, 1, 0] = 400;
age[0, 1, 1] = 500;
age[0, 1, 2] = 600;
// Printing the array by using three for loops
for (int x = 0; x < age.GetLength(0); x++)
{
for (int y = 0; y < age.GetLength(1); y++)
{
for (int z = 0; z < age.GetLength(2); z++)
{
Console.Write(age[x, y, z]);
Console.WriteLine();
}
Console.WriteLine();
}
Console.WriteLine();
}