|
-Laboratoriya. Bir o‘lchamli massivlar bilan ishlash
|
bet | 134/154 | Sana | 08.01.2024 | Hajmi | 5,29 Mb. | | #131939 |
Bog'liq Majmua13-Laboratoriya. Bir o‘lchamli massivlar bilan ishlash.
C# dasturlash tilida massivlar 2 xil bo’ladi: bir o’lchamli va ko’p o’lchamli
Bir o’lchovli massivlar: bir xil turdagi berilgan ketma-ketliklar bo’lib quyidagicha e’lon qilinadi
int[] intArray= new int[5];
double[] doubleArray = new double[5];
char[] charArray = new char[5];
bool[] boolArray = new bool[2];
string[] stringArray = new string[10];
yoki o’lchami biron N butun son bo’lsa
int N = Int32.Parse(Console.ReadLine());
double[] doubleArray = new double[N];
Massiv elementlariga qiymat berish
int[] staticIntArray = new int[3] { 1, 3, 5 };
int[] staticIntArray = new int[3];
staticIntArray[0] = 1;
staticIntArray[1] = 3;
staticIntArray[2] = 5;
string[] strArray = new string[] { "Mahesh Chand", "Mike Gold", "Raj Beniwal", "Praveen Kumar", "Dinesh Beniwal" };
int[] staticIntArray = new int[3];
staticIntArray[0] = 1;
staticIntArray[1] = 3;
staticIntArray[2] = 5;
// Elementlarni chop etish
Console.WriteLine(staticIntArray[0]);
Console.WriteLine(staticIntArray[1]);
Console.WriteLine(staticIntArray[2]);
string[] strArray = new string[] {
"Mahesh Chand",
"Mike Gold",
"Raj Beniwal",
"Praveen Kumar",
"Dinesh Beniwal"
};
// Ekranga chop etish
foreach (string str in strArray)
{
Console.WriteLine(str);
}
Ikki o’lchamli va ko’p o’lchamli massivlar
int[,] numbers = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
string[,] names = new string[2, 2] { { "Rosy", "Amy" }, { "Peter", "Albert" } };
int[,] numbers = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
string[,] names = new string[,] { { "Rosy", "Amy" }, { "Peter", "Albert" } };
int[,] numbers = new int[3, 2];
numbers[0, 0] = 1;
numbers[1, 0] = 2;
numbers[2, 0] = 3;
numbers[0, 1] = 4;
numbers[1, 1] = 5;
numbers[2, 1] = 6;
Console.WriteLine(numbers[0, 0]);
Console.WriteLine(numbers[0, 1]);
Console.WriteLine(numbers[1, 0]);
Console.WriteLine(numbers[1, 1]);
Console.WriteLine(numbers[2, 0]);
Console.WriteLine(numbers[2, 2]);
|
| |