Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Loops-Nested/C-sharp/loops-nested-1.cs
Normal file
26
Task/Loops-Nested/C-sharp/loops-nested-1.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
int[,] a = new int[10, 10];
|
||||
Random r = new Random();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
a[i, j] = r.Next(0, 21) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
Console.Write(" {0}", a[i, j]);
|
||||
if (a[i, j] == 20) {
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Done:
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
25
Task/Loops-Nested/C-sharp/loops-nested-2.cs
Normal file
25
Task/Loops-Nested/C-sharp/loops-nested-2.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
int[,] a = new int[10, 10];
|
||||
Random r = new Random();
|
||||
|
||||
// prepare linq statement with two 'from' which makes nested loop
|
||||
var pairs = from i in Enumerable.Range(0, 10)
|
||||
from j in Enumerable.Range(0, 10)
|
||||
select new { i = i, j = j};
|
||||
|
||||
// iterates through the full nested loop with a sigle foreach statement
|
||||
foreach (var p in pairs)
|
||||
{
|
||||
a[p.i, p.j] = r.Next(0, 21) + 1;
|
||||
}
|
||||
|
||||
// iterates through the nested loop until find element = 20
|
||||
pairs.Any(p => { Console.Write(" {0}", a[p.i, p.j]); return a[p.i, p.j] == 20; });
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue