Skip to content

Commit ef2d0d2

Browse files
authored
Add files via upload
1 parent 103c09b commit ef2d0d2

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

LU1/Ex1/ParallelPrograming.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Ex1
9+
{
10+
class ParallelPrograming
11+
{
12+
public static void Main() {
13+
14+
var cores = Environment.ProcessorCount;
15+
16+
Stopwatch sw = new Stopwatch();
17+
18+
int[] dataItems = new int[100000000];
19+
double[] resultItem = new double[100000000];
20+
21+
for (int i = 0; i < dataItems.Length; i++)
22+
{
23+
dataItems[i] = i;
24+
}
25+
26+
sw.Start();
27+
for (int i = 0; i < dataItems.Length; i++)
28+
{
29+
resultItem[i] = Math.Pow(dataItems[i], 2);
30+
}
31+
sw.Stop();
32+
Console.WriteLine(sw.ElapsedMilliseconds);
33+
sw.Reset();
34+
35+
sw.Start();
36+
Parallel.For (0, dataItems.Length, i => {
37+
resultItem[i] = Math.Pow(dataItems[i], 2);
38+
});
39+
sw.Stop();
40+
Console.WriteLine(sw.ElapsedMilliseconds);
41+
42+
Console.WriteLine("Press enter to finish");
43+
Console.ReadLine();
44+
}
45+
}
46+
}

LU1/Ex1/ProgrArrayListExample.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Ex1
9+
{
10+
class ProgrArrayListExample
11+
{
12+
/*
13+
public static void Main()
14+
{
15+
ArrayList list = new ArrayList();
16+
list.Add("Hello");
17+
list.Add(5);
18+
list.Add(3.14);
19+
list.Add(DateTime.Now);
20+
21+
for (int i = 0; i < list.Count; i++)
22+
{
23+
object value = list[i];
24+
Console.WriteLine("Index = {0}; Value = {1}\n", i, value);
25+
}
26+
}
27+
*/
28+
}
29+
}

LU1/Ex1/Program.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Ex1
8+
{
9+
class Program
10+
{
11+
/*static void Main(string[] args)
12+
{
13+
int[][] myJaggedArray = {
14+
new int[] {5, 7, 2},
15+
new int[] {10, 20, 40},
16+
new int[] {3, 25}
17+
};
18+
19+
int[][,] jaggedOfMulti = new int[2][,];
20+
jaggedOfMulti[0] = new int[,] { {5, 15}, {125, 206}};
21+
jaggedOfMulti[1] = new int[,] { {3, 4, 5}, {7, 8, 9} };
22+
23+
Console.WriteLine("Enter the number of rows: ");
24+
int rows = int.Parse(Console.ReadLine());
25+
26+
Console.WriteLine("Enter the number of cols: ");
27+
int cols = int.Parse(Console.ReadLine());
28+
29+
int[,] matrix = new int[rows, cols];
30+
31+
Console.WriteLine("Enter the cells of the matrix:");
32+
33+
matrix = fillMatrix(rows, cols);
34+
35+
printMatrix(matrix, rows, cols);
36+
37+
38+
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
39+
foreach (int i in numbers)
40+
{
41+
Console.Write(" " + i);
42+
}
43+
Console.WriteLine();
44+
45+
46+
}
47+
48+
private static void printMatrix(int[,] matrix, int rows, int cols)
49+
{
50+
for (int row = 0; row < matrix.GetLength(0); row++)
51+
{
52+
for (int col = 0; col < matrix.GetLength(1); col++)
53+
{
54+
Console.Write(" " + matrix[row, col]);
55+
}
56+
Console.WriteLine();
57+
}
58+
}
59+
60+
private static int[,] fillMatrix(int rows, int cols)
61+
{
62+
int[,] matrix = new int[rows, cols];
63+
64+
for (int row = 0; row < rows; row++)
65+
{
66+
for (int col = 0; col < cols; col++)
67+
{
68+
Console.Write("matrix[{0}, {1}] = ", row, col);
69+
matrix[row, col] = int.Parse(Console.ReadLine());
70+
}
71+
}
72+
return matrix;
73+
}
74+
*/
75+
}
76+
}

0 commit comments

Comments
 (0)