.


:




:

































 

 

 

 


foreach( in )




3

() C#.

FOR:

( N , N ..);

.

. й1 1.3.

1. (. 3.7).

2. FOR (. 3.5).

3. ( N , N ..) "" .

4. "", (. 3.6) .

5. "" .

6. (. 3.9).

7. (. . 1.10)

() FOR FOREACH

- .

. for Basic Pascal .

for :

For( ; ; )

{

}

, . , , , for.

, , if.

() - (, ).

for:

1. , .

2. . , . , , , , . , .

. ( ) :

for(;;) { }

15 30 . F=C*1.8+32;

class Program

{

static void Main(string[] args)

{

int i;

double F=0;

Console.WriteLine(" ");

for (i = 15; i <= 30; i++)

{

F = i * 1.8 + 32;

Console.WriteLine("={0} ={1}", i, F);

}

Console.Write("Press any key to continue... ");

Console.ReadKey(true);

}

}

 

foreach

, C/C++. C#. : .

:

foreach( in )

{

//

}

;

;

in ;

. . , , .

: .

, , , , .

3.6. ""

, . .

, .

, :

_ [] _;

 

:

_ = new _ [ _ ];

 

- .

, 5 :

double[] x;

x = new double[5];

 

:

double[] x = new double[5];

 

, , .. ( 4,5,3,2,1):

double[] x = new double[5] { 4, 5, 3, 2, 1 };

 

, . : , .

:

double[] x = { 4, 5, 3, 2, 1 };

 

, ( ).

5 .

. n . . .

double []x = new double[5];

int i, n = x.Length;

Console.WriteLine(" {0} :", n);

for(i = 0; i < n; i++)

{

Console.Write("x[{0}] = ", i);

x[i] = double.Parse(Console.ReadLine());

}

double s = 0;

for(i = 0; i < n; i++)

s += x[i];

s /= n; //

for(i = 0; i < n; i++)

x[i] -= s;

Console.WriteLine(" :");

foreach(double r in x)

Console.WriteLine(r);

Console.Write("Press any key to continue... ");

Console.ReadKey(true);

 

()

 

. , , . . A[2x3]. .

1) :

double[,] a = new double[2, 3];

 

2) , :

double[,] a = new double[2, 3] { { 2, 4, 0 }, { 1, 6, 4 } };

 

, , , .

:

double[,] a = new double[,] { { 2, 4, 0 }, { 1, 6, 4 } };

 

. A[2x3], .. . :

 

class Program

{

static void Main(string[] args)

{

const int n = 2;

const int m = 3;

double [,]a = new double[n, m];

int i, j;

Console.WriteLine(" A[{0}*{1}]:", n, m);

for(i = 0; i < n; i++)

for(j = 0; j < m; j++)

a[i, j] = double.Parse(Console.ReadLine());

double max = Math.Abs(a[0, 0]);

for(i = 0; i < n; i++)

for(j = 0; j < m; j++)

if(Math.Abs(a[i, j]) > max)

max = Math.Abs(a[i, j]);

Console.WriteLine("max = {0}", max);

for(i = 0; i < n; i++)

for(j = 0; j < m; j++)

a[i, j] /= max;

Console.WriteLine("M A[{0}*{1}] :", n, m);

for(i = 0; i < n; i++)

{

for(j = 0; j < m; j++)

Console.Write(a[i,j]+"\t ");

Console.WriteLine();

}

Console.Write("Press any key to continue... ");

Console.ReadKey(true);

}

}

. , . :

 

double[,,] V = new double[2, 3, 3];

 

, 3x3.

:

double[,,] V = new double[2, 3, 3]

{

{{2,4,0}, {1,6,4}, {5,3,3}},

{{2,1,6}, {1,8,5}, {0,2,7}}

};

 

:

double[,,] V =

{

{{2,4,0}, {1,6,4}, {5,3,3}},

{{2,1,6}, {1,8,5}, {0,2,7}}

};

 

, , , .

 

 

, , Array. . . x , a .

1) Length . , :

for (i = 0; i < x.Length; i++)

Console.WriteLine(x[i]);

2) Rank . :

int r = a.Rank;

Console.WriteLine("=" + r);

1) Sort() . . :

- :

Array.Sort(x);

 

- i- , k ( : 3 , 2-):

Array.Sort(x, 2, 3);

 

2) Reverse() :

Array.Reverse(x);

 

:

Array.Reverse(x, 0, 3);

 

3) BinarySearch () , . , . :

int t = 4;

int j = Array.BinarySearch(x, t);

 

4) IndexOf () , , 4 x. , .

 

int j = Array.IndexOf(x, 4);

 

5) LastIndexOf () , , 4 x. , .

int j = Array.LastIndexOf(x, 4);

 

6) GetLength () .

0. , :

for (i = 0; i < a.GetLength(0); i++)

for (j = 0; j < a.GetLength(1); j++)

a[i, j] = double.Parse(Console.ReadLine());

1.) n!

)

) , .

2.) .

)

) n´m.

3.) .

) 0.

) .

4.) .

) (20)

) .

5.) .

)

) .

6.) .

) 2 2.

) .

7.) .

) , p

) (5´5)

8.) .

) .

) , .

9.) .

) , "-3" "+3", 0.

) .

10.) .

) (25).

) .

11.)

) (20) (20) .

) .

12.) .

) .

) .

13.) .

) .

) .

14.) .

) 0 15 Random , 7.

) .

15.) .

) (10).

) .

16.)

)

) B, A.

17.) .

) 0, 1.

) B, A.

18.)

) n .

) .

19.) .

) 0 10 Random .

) (5´5)

20.) .

)

) .

 

(. . 1.10)

1. FOR FOREACH?

2. FOR?

3. FOR?

4. ?

5. FOR?

6. ""?

7. ?

8. -, -, n- ?

9. () -, , n- ?





:


: 2015-10-19; !; : 1062 |


:

:

.
==> ...

1556 - | 1387 -


© 2015-2024 lektsii.org - -

: 0.091 .