Загрузил Osman Mirzoev

Основы программирования на С#

Реклама
«
»
.
.
.
C#»
«
» «
2011
»
681.3.06
2008 .
«
:
»
«
»,
.,
. .
;
«
.
»
. .
;
C#
«
»
»
:
.,
, 2011
»
C#,
-
.
1, 2
.
.
,
3, 4
5, 6
7,
.
.
-
.
,
,
. .
-
.
©
.
,
.
2
,
.
© «
,
», 2011
.
.NET
,
.
,
-
,
,
-
.
,
,
,
-
,
,
.
:
,
;
,
,
,
;
;
,
;
.
.NET (
«
»)
,
Visual Studio.NET,
-
,
,
,
.
:
3
;
;
.
;
.
.NET
.
,
,
,
-
MSIL (Microsoft Intermediate Language),
,
,
.
,
,
(Common Language
IL),
Runtime, CLR).
CLR
.
JIT-
CLR
,
.
IL
,
«just in time»,
JIT
«
»,
,
.
4
-
.
.NET
. 1.
(IL
)
JIT
(IL
)
. 0.1.
.NET
dll,
IL
.
,
,
.
-
,
,
.
CLR
,
5
,
-
.
.
.NET
.NET.
,
–
.NET
,
-
.
,
-
#,
(
).
-
.
,
,
.
.
»
,
,
,
«
-
,
.
-
,
,
,
.
.
-
.
,
.
,
.
.
.
6
.
,
.
.
-
,
,
-
.
.
(
«
»).
,
«
»,
-
.
,
,
.
:
-
.
,
.
-
,
.
,
,
,
.
,
.
7
-
,
-
,
.
,
.
:
;
;
-
.
,
,
-
.
.
,
,
-
.
,
,
,
.
,
,
,
,
,
,
,
-
,
.
,
.
-
,
.
8
,
«
(
),
,
,
-
,
-
».
:
;
,
;
;
;
.
-
,
,
.
,
-
.
,
.
,
#, Java,
.
.
++, Delphi
,
«
», «
»
», «
. .
9
-
,
-
,
.
,
.
.NET,
,
-
.NET,
object
.
,
.
,
.
-
.
System.Net
,
-
, System.Win-
,
dows.Forms
,
,
. .
,
-
.
Visual Studio.NET
Visual Studio.NET
,
,
,
.NETMicrosoft
: #, VB.NET, ++
.NET
,
.
J#.
.
,
-
10
.
.NET,
ron, Perl Python.
, Ada, COBOL, Delphi, Eiffel, Fortran, Lisp, Obe.
:
,
.
Windowsdows,
Visual Studio.NET
,
:
,
Win-
,
,
.;
«
»,
;
,
;
,
.
,
-
,
.
Microsoft Visual Studio 2010 (
Microsoft Visual Studio 2010
Express –
#).
:
,
;
Professional –
,
,
11
-
,
;
Premium –
-
,
;
Ultimate –
Visual Studio,
,
,
.
. 0.2.
12
,
-
2010
Microsoft Visual Studio
.
,
#,
-
,
,
#
-
.
.
,
. 2.
(
,
. .)
.
,
C#
.
.
. 0.3.
13
,
.
(
•
,
).
,
:
,
(Classl.cs).
-
,
.
,
,
.
Windows
.
-
,
.
csproj),
(
sln)
(
(Classl.cs).
,
,
.
-
,
.
(
)
,
)
(2
,
-
.
:
,
.
,
,
.
.
14
-
(
,
,
1).
.
-
.
1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Classl.
/// </summary>
class Classl
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
//
// TODO: Add code to start application
// here
//
}
15
}
}
using System
System
).
using System.Collections.Generic;
using System.Linq;
using System.Text;
-
.
.
namespace
ConsoleApplica-
,
tionl.
,
-
,
,
.
,
,
.
#
,
.
,
Class.
-
class,
(
).
16
,
!!!
.
,
.
-
,
,
,
.
,
.
Main.
Main
.
.
:
[
]
( [
] )
{
:
,
}
«
»
-
.
,
.
Main
:
// TODO: Add code to start application here
:«
,
».
(
!)
Console.WriteLine("
-
!!!");
Console –
System.
WriteLine
17
.
,
-
.
,
Console
,
Console.
,
,
.
Enter
.
.
-
,
.
,
2.
,
*
,
,
,
,
,
.
•
Save
(
).
,
.
F5 (
•
,
18
).
!!!
,
.
,
,
Ctrl+F5.
.
,
.
19
-
1.
(
.
.
)
:
-
-
,
«
»
:«
(
»
?
);
-
,
)
;
(
)
.
2011
.
4,
:
-
,
» ),
(
(
:«
»),
,
-
,
,
;
,
-
(
,
-
);
-
(
.
,
-
);
,
,
,
;
,
;
20
-
-
,
,
-
.
2.
3.
.
.
4.
,
(
).
5.
.
.
,
.
-
.
.
,
.
6.
,
,
,
:
».
.
«
.
.
.
21
-
1.
C#
,
.
1.
.
C#
,
System.
,
string –
-
System.String,
int
System.Int32.
–
:
;
;
1.1
NET
)
bool
System.Boolean -
-
Int
System.Int32
32
shot
System.Int16
16
byte
System.Byte
8
sbyte
System.SByte
8
long
System.Int64
64
float
System.Single
7
32
double
System.Double
15
64
string
System.String
-
shar
System.Char
16
Unicod
object
System.Object
22
-
;
;
(object).
1.1.
NET Framework
–
System.Object.
:
.
,
.
,
.
-
null.
,
,
,
-
.
-
,
.
.
#.
,
,
,
,
.
Visual Studio
, Microsoft Visual Basic, Microsoft Visual C#).
C#,
Visual Studio,
#
C#
23
.
.
(
-
Visual Studio.NET
C#
–
-
cs).
,
Main.
,
C#
++,
,
,
.
-
,
,
,
.
Main.
C#
,
string –
,
,
.
-
,
,
C#.
-
:
static void Main(string[] args)
{
}
static
,
Main
,
,
.
,
void.
,
Main
1.
int.
.
static void Main()
24
{
Console.WriteLine("
!\n
\"
\"!!!");
}
.
Debug\Start Without Debugging.
.
: Press any key to continue,
.
« -
.
»
,
.
Debug\Start Debugging,
.
-
,
.
Console.Read();
.
int.
–
,
-12, 5,
,
0(
32
25
).
-
-12L
8
), 5u
64
)
.
float(32
)
f
double (64
-
,
-
F 1.2, -1.234,
-
)
«d»
«D»,
: 1234.5678, 12.3d.
.
.
float(32
f
)
,
F: 1.2E-3f
double (64
.
0.0012),
) -1.34E5
-
-134000)
-
char
.
Unicode (‘a’)
16(
-
(‘\r’),
(‘\t’),
(‘\f’),
),
-
.
–
,
string.
,
!\n
,
,
\"
\"!!!"
true
.
(«
false («
»)
»).
,
C#
.
.
,
,
,
26
-
const float p = 3.14159f
–
,
-
.
.
,
.
.
,
.
,
.
Long, LONG, long –
.
-
,
.
.
-
(
).
: MaxLen, iMaxLen, Max_Len
: 2Len, Le#
:
int a =
-14;
float c = -0.00151f;
//
32
//
32
//
double i = 1234.56789;
//
64
//
bool l = false;
//
string name = "Petrov"; //
27
16
–
(
,
,
-
),
.
:
2 * 2 + 1
5
1 / 2 – 3
-3
1. / 2 – 3
-2.5
(
1.2):
y = 2*x*x + 3*x – 1.
« = »,
y.
:
string kaf
=
“
” + “
”;
,
“
”,
kaf.
1.2
+
*
/
%
28
+
,
-
,
.
%,
10 % 3
-
1.
,
10f / 3f
,
3,333333.
#
Math
,
System.
-
,
VS
.
, . .
.
.
,
,
.
,
-
Math.Abs(),
,
: double Math.Abs
7
(double x), float Math.Abs (float x), int Math.Abs(int
x),
. .(
1.3)
1.3
1.
Math.Abs(
)
29
2.
Math.Ceiling(
3.
Math.Cos(
4.
Math.
5.
Math.Exp(
6.
Math.Floor(
7.
Math.Log(
8.
Math.Log10(
9.
Math.Max(
)
)
)
)
)
)
1,
2)
10. Math.Min(
1,
2)
11. Math.PI
12. Math.Pow(
1,
2)
13. Math.Round(
)
Math.Round(
,
)
14. Math.Sign(
15. Math.Sin(
)
)
16. Math.Sqrt(
17. Math. an(
)
)
Y
2.
using System;
using System.Collections.Generic;
30
cos x
1 x2
x = 2,5
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Example2
//
// Example2
{
static void Main()
{
double p = 3.14159;
double x = 2.5;
double y = Math.Cos(p * x)/(1 + x*x);
Console.WriteLine();
Console.WriteLine(" x = {0} \t y = {1} ",
x, y);
}
}
}
:
Console.WriteLine()
.
.
31
-
.
.
(
.
)
(
#
)
.
-
.
,
Console,
System.
ReadLine,
Console.
-
,
(string).
:
static void Main()
{
string s = Console.ReadLine();
Console.WriteLine(s);
}
.
:
static void Main()
{
string s = Console.ReadLine();
int x = int.Parse(s); //
//
Console.WriteLine(x);
}
:
32
static void Main()
{
//
}
int x = int.Parse(Console.ReadLine());
Console.WriteLine(x);
int.Parse(),
.
int
,
,
float.Parse()
le.Parse().
doub-
,
-
,
System.FormatExeption (
).
WriteLine,
Console,
.
(
1.4):
1.4.
-
Console.WriteLine(x);
Console.WriteLine("x="
+
x
+"y=" + y);
,
"x=",
33
-
x,
" ="
Console.WriteLine("x={0}
y={1}", x, y);
,
,
{0}
x,
{1} –
WriteLine
Write,
-
.
.
,
.
-
,
(
)
,
,
(
(
\a
\t
\b
\v
\f
\\
34
1.5):
1.5.
,
).
-
\n
\'
\r
\"
3.
,
.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//
OperatingSystem os =
System.Environment.OSVersion;
Console.WriteLine("Platform:
{0}",os.Platform);
System.Console.WriteLine("The
date and time is " +
System.DateTime.Now);
//
System.Console.ReadLine();
}
}
}
35
current
4.
Y
cos x
1 x2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lab0
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("The
current
date
"
and
time
is
+
System.DateTime.Now);
double pi = 3.14159;
Console.WriteLine("Input x =\r");
double x =
Convert.ToDouble(Console.ReadLine());
double y = Math.Cos(pi * x)/(1 + x*x);
Console.WriteLine(" x = {0} \t y = {1}
",x,y);
36
Console.ReadKey();
}
}
}
2.
.
1.
,
-
,
(
3).
2.
,
Console.ReadLine() (
4)
.
1.6;.
1.6
.
1
A
4
9
ln(
x)
3
7
e
sin(1,3x 0,7)
2
B
(x
sine x
-0,75
arcsin(cos x )
C 3,7 5 xcos(3,5 x)
5
37
(5 x)
-0,018
1,2
2,23
3
-0,0049
2,5
4
7 3
)
6
0,31
3
3,2
-0,018
4
5
6
7
8
9
10
11
12
D
E
cos x 5
3
e
6,3sin(1,3 x
F cos1,5x e
G
H
I
J
3
x
5
) x
sin(x 4 )
3
3
)sin1,7x
4
e
sinln(x 2) cos( ln(x
4sin(15e
e
4x
5
x
8
10,2) 9cose
2sin(7ln(x
x
2
9
4
x
x
5
arctg 2 cos2x
3
K 1,3e
L
1,7arctg(
14
2
7 3
)
3
(x
-1,318
1,5
0,40
0,016
1,5
7
6
2,26
x
5
2,09
0,235
1,2
0,920
1,7
5
))
3
x
-0,26
x
5
x
-0,0049
0,25
5
3
-0,61
-0,012
0,5
0,97
5
))
3
-0,0024
-0,5
2 x
6
cos(
1,4)
3
11
2,81
0,253
1,25
2,03
4 sin arctgx
ln
7
2
1,043
1,7
1,97
x
13
-0,35
4
M e
arcsin cosx
3
sin(x 5 )
3
F cos1,5x e
0,0017
0,7
0,96
x
38
7
6
1,23
-0,528
arctgx
15
O arccos sin(3x 1,3) xe
16
4
P 1,3x 2,5sin(5
arctgx 0,7)
3
17
18
x
2
x
Q e cos(2x 0,3)
R
e
0,7
1,32
-0,5
-0,71
0,1 xcos(3x 1,5)
20
21
22
23
24
25
S 5sin(x 0,3)
T
2 e
1,1
x
20,7 (sin (1,2x) arccos ) e1,5x
8
sin
W
0,1x
-0,0082
2
2,07
-0,1699
2
2x
x
U 1 sin
cos
3
3
V
x
-1,485
1,2
0,62
19
-4,197
1,53
2,7 x
2,15
x
2
0,0252
0,7
-0,73
2
0,307
e
2x
5
2sin
cos
e
4,5x
x
2
0,2
4
5
ln(
3
0,69
x)/1,5
x
2
X
cos(4ln(x
7
)) ln(4
3
Y
1
arcsin
3
x
1,5sin ln(x
7
x
4
x
4
)/3
7
11
39
-0,0009
0,23
7
) e
4
(x
0,0038
1,15
1,28
4
3
5
1,35
4
)
3
-0,63
6,0827
1,35
1,78
0,0064
2,3
0,23
1,4
-0,0021
26
Z
x
cos
3
e
27
70
A1 8x/(
3
28
15
1
B1
(
9
3
29
30
x) e
x )/e
3
5
7
C1 ln(
x) sin
3
3
1
D1
e
3
cos2 x
x
-1,0396
0,96
sin 2 (
7
7
6
x
5
-0,23
4
9
(x 1) 2
2x
)
3
x
3
1
7
x
9
4
/(1 ln(x 3))
7
5
40
1,83
0,2601
-0,5
0,47
-0,0073
1,2
0,66
-0,0001
-0,5
0,71
1,4
-0,0012
2
,
.
.
1.
System.Console.Write()
,
System.Console.WriteLine(),
.
,
-
.
int
value:
int value = 250;
:
System.Console.WriteLine ("value
:
=" + value);
value = 250
value,
(
5):
System.Console.WriteLine("value = {0, 5}", value);
–
0,
value
System.Console.WriteLine().
-
,
5.
.
41
-
.
,
.
:
int a = -12;
int b = 20;
System.Console.WriteLine("a = {0,
a,
4}, b =
{1,
3}",
b);
: a = -12, b = 20
.
,
double
myDouble: double myDouble = 1234.56789;
myDouble,
,
:
System.Console.WriteLine("myDouble = {0,
10:f3}";
myDouble);
f3
,
(
f) ,
.
float
decimal.
:
float myFloat = 1234.56789f;
System.Console.Write("myFloat
=
{0,
10:f3}",
{0,
10:f3}",
myFloat);
decimal myDecimal = 1234.56789m;
System.Console.Write("myDecimal
myDecimal);
42
=
:
myFloat = 1234.568;
myDecimal 1234.568;
WriteLine
{n, w:
k} –
Write
n
WriteLine,
-
, w –
–
,
(
),
k–
.
-
.
2.1.
2.1
W
W:Fk
W:Ek
W
W
F, E (
-
. 2.2) –
w–
.
(
,
),
43
-
k –
.
-
:
,
F);
(
,
E
G).
:
2.2
C
c
.
.
.
NumberFormatInfo
D
E
d
(
)
.
e
.
6
F
f
G
g
(
,
.
)
44
N
n
.
– 2,
,
X
x
P
p
1.
.
public static void Main()
{
int a =
-14;
float c = -0.00151f;
double i = 1234.56789;
bool l=false;
string name="Petrov";
System.Console.WriteLine("name = {0, 6}, l =
{1, 4}", name,l);
System.Console.WriteLine("a ={0, 4}, c =
{1,10:f5}, i = {1,20:e8}", a,c,i);
System.Console.WriteLine(" ");
System.Console.WriteLine("
Enter");
System.Console.ReadLine();
}
45
2.
.
public static void Main()
{
int a;
// =
-14;
float c;
// = -0.00151f;
double i;
// = 1234.56789;
bool l;
// = false;
string name; //="Petrov";
Console.WriteLine("Input
");
name = Console.ReadLine();
Console.WriteLine("Input
");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input c");
c = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Input i");
i = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input l");
l = Convert.ToBoolean(Console.ReadLine());
46
System.Console.WriteLine("
\n name = {0, 6}, l = {1, 4}",
name,l);
System.Console.WriteLine("a ={0, 4}, c =
{1,10:f5}, i = {2,20:e8}", a,c,i);
System.Console.WriteLine(" ");
System.Console.WriteLine("
Enter");
System.Console.ReadLine();
}
#,
.
–
,
,
,
)
).
(
(stream)
.
( , -
,
,
-
.
.
,
.
,
-
47
.
,
,
,
.
int-, double-, short-
,
,
,
,
-
.
#Stream
System.IO.
Stream
.
-
Stream (
, FileStream) "
StreamWriter
"
StreamReader.
-
.
StreamWriter
.
.
,
StreamWriter
,
:
StreamWriter fileOut = new StreamWriter(new
FileStream("text.txt", FileMode.Create,
FileAccess.Write));
:
FileStream(string filename, FileMode mode,
FileAccess how)
:
48
-
filename
1.
mode
,
;
how,
2.
,
FileAccess:
FileAccess.Read FileAccess.Write FileAccess.ReadWrite -
;
,
;
.
:
StreamWriter(string name),
name
.
,
-
:
StreamWriter fileOut = new
StreamWriter("c:\temp\t.txt");
StreamWriter:
StreamWriter(string name, bool appendFlag),
name
appendFlag
;
true –
,
-
false –
-
.
:
StreamWriter fileOut=new StreamWriter("t.txt", true);
fileOut
WriteLine.
:
fileOut.WriteLine("test");
t.txt
test.
49
StreamReader
.
:
-
StreamReader(Stream stream),
stream
ArgumentEx-
.
ception,
stream
.
StreamWriter
,
:
StreamReader fileIn = new StreamReader(new
FileStream("text.txt", FileMode.Open,
FileAccess.Read));
StreamWriter
Reader
Stream-
,
-
:
StreamReader (string name);
name
.
-
:
StreamReader fileIn=new StreamReader
("z:\temp\t.txt");
C#
Unicode.
,
,
,
,
,
,
StreamReader:
StreamReader fileIn=new StreamReader
("z:\temp\t.txt", Encoding.GetEncoding(1251));
Encoding.GetEncoding(1251)
Windows-1251 (
50
,
ASCII,
)
Uni-
code. Encoding.GetEncoding(1251)
System.Text.
fileIn
-
ReadLine.
ReadLine
,
null.
.
Close().
,
,
.
,
Stream-
Writer
StreamReader.
3.
.
static void Main()
{
string s;
double x, y;
StreamWriter f = new StreamWriter("out.txt");
StreamReader f1 = new StreamReader("in.txt");
f.WriteLine("
\n");
metka: s = f1.ReadLine();
if (s == null) goto metka1;
x = Convert.ToDouble(s);
51
y = Math.Sqrt(x * x / (2 + Math.Exp(4 *
Math.Log(x))));
f.WriteLine("
x = {0:F3}
y =
{1:e3} \n", x, y);
goto metka;
metka1: f.WriteLine("
{0} \n", s);
f.Close();
f1.Close();
}
in.txt
0,11
0,5
1
out.txt
x = 0,110
y = 7,778e-002
x = 0,500
y = 3,482e-001
x = 1,000
y = 5,774e-001
2.
1)
A, I, C, L, Name
52
(
2.3).
2)
2.4.
8
LAB2.TXT.
.
-
LAB2.RES
(
2.5) .
2.3
A
I
C
1
-14
-104
-0,00151
2
99,35
72
1995
3
0,086
-19
4,025
4
34
-6124
3,2 105
5
5,008
229
0,019
6
3,5 10-4
1989
-380,08
7
0,095
-1
1996
8
1,0074
102
107,7
9
993,285
112000
2,3 10-4
10
-2,1
444
103
11
3,125
6006006
-13,24
12
-45,077
30
25 1012
13
12,97
1002
-999,7
14
-0,09
2004
399,44
15
-142
-104
-0,00151
16
9,35
- 5072
19,95
17
0, 86
-19726
4,025
53
L
N
18
34
-6
3,2 103
19
5,008
-229
-0,019
20
3,5 10-4
1989
-380,08
21
0,095
-12
1996
22
1,0074
102
107,7
23
993,285
112000
2,3 10-4
24
-2,1 103
444
10-3
25
3,125
6007007
-13,24
26
-45,07
123
25 1012
27
89,09
1000
999,002
28
-99,78
11
-1,774
29
7,99
-30077
1000
30
0,124
-100400
-9000
2.4
x
x*
y*
xmin
xmax
2
-0,176
-3
3
1
1
1 x2
y
1 x4
2
y
sin x
x2 1
1,57
0,406
-2
2
2
3
y
2
x2
3,14
0,935
-2
4
3
1
4,5
0
2,5
4
4
y 4x
1
x 1
54
5
sin 2 x
y
x 1
1,57
1,75
1,5
5
1
6
x2 5 x 4
y
x2 1
2
-0,4
-2
3
2
1
-1
1
3
1,57
0,299
-2
2
4
-1
-2,7
0
2,5
1
0,5
1,9
-3
3
2
-0,6
0,43
-1
1,5
3
0,14
0,0027
-2
2
4
1,5
0,242
0
3
1
1
2,4
0
4
2
1
1,57
-2
2
3
3 sin x
1,57
-0,53
-0,5
2
4
cos
0,5
0,5
-1,5
1,5
1
x
1
0,369
0
3
2
3 x2
1,2
-1,75
-1,3
1,3
3
1,2
0,262
-2
2
4
2x
2x
e
e
y 2
e e
sin x
y
x 1
x
y e x sin( )
2
2
y
( x2
)
7
2
8
2
2
9
10
3
2
11
y
ln
12
y
x cos ( x 3)
14
20
1
e
2
x
x2
y
y
x (1
y
y
x
2
x 1
3
y 2 arctgx
18
19
3
y
16
17
x
y
13
15
1
sin
xe
tgx
x
x
x)
y e x sin 2 x
55
y ln( x 1 ) cos 2 x
21
22
y
x (1
y
23
24
cos
2
e
y
x)
1
2
xarctgx
y x sin x
25
26
y
x
3
5x
2
4
x
3
1,077
1
4
1
-0,5
-0,5
-1,5
1,5
2
0,25
1,75
-2
2
3
1
1,4
-2
3
4
0,5
-0,5
-2
3
1
0,5
0,875
-1
4
2
27
y 1 2 cos x sin 2 x
0
3
-2
2
3
28
y cos 2 x - 2
0
-1
-2
2
4
-1
-7
-2
3
1
1
-4
-2
5
2
29
y
30
y
2x
2( x
3
5x
2
3
9x
2
)
1
3
2.5
7890123456789012345678901234 –
1
I---------------------------------------I
I
X
I
I
I---------------------------------------I
I X =…
I Y =…
I
I X =…
I Y =…
I
I---------------------------------------I
: < . . .>
2
56
*******************************
* X =…
*
Y=…
*
*******************************
* X =…
* Y =…
*
*******************************
: < . . .>
3
+---------------------------------------+
+
+
+
+---------------------------------------+
+ X =… + Y =..
+
+ X =… + Y =…
+
+
...
+
...
+
+---------------------------------------+
: < . . .>
4
:
: <
57
Y(…) = …
Y(…) = …
. . .>
3
.
1.
,
,
-
,
,
.
,
.
.
,
.
-
.
,
-
,
,
.
-
.
,
.
.
#,
,
58
if,
C#
,
IF
./
if
if (
),
,
-
,
.
.
.
if (
)
{
//
(
//
)
,
}
//
//
,
.
,
.
boolean.
-
.
true (
),
.
false (
-
)
.
59
1.
//
, a
//
b,
max
max = b;
if (a > b)
{
max = a;
}
,
b,
max.
max
,
-
a.
,
,
.
2.
max = b;
if (a > b){max = a;}
.
,
(
.
3.
3).
max = b;
if (a > b) max = a;
60
if-els (
-
)
,
(
),
.
.
If (
)
{
//
,
-
//
1.
}
els
{
//
(
//
)
,
-
//
2.
}
//
//
,
.
-
true (
1.
),
,
2
.
false
.
(
1
),
,
2.
61
-
,
.
,
-
.
4.
If (a > b)
{
max =
; //
,
min = b; //
a>b
.
}
els
{
max = b;
//
min = a;
//
,
a > b
.
}
//
//
,
.
a > b,
min -
a,
max
b,
b,
max
a.
,
5.
5.
if (a > b)
{
62
min –
max =
;
min = b;
}
else
{
max = b;
min = a;
}
,
,
6.
6.
if (a > b) max =
;
else max = b;
if
,
(
,
)
-
,
if.
if,
if,
if.
if (
1
)
{
//
//
1
-
,
1.
}
63
lse
//
//
if.
{
//
if.
if (
2
)
{
//
2
//
//
2.
}
Else
{
//
,
//
2
//
,
//
3.
}
}
//
if
1
-
,
1,
,
,
-
if.
if.
2
if
-
,
2,
,
,
64
-
if.
2
,
3.
-
if.
7.
...
if (
< -1)
{ n = 1; }
else
{
//
if.
if (
> 1)
{ n = 2; }
else
{ n = 0; }
//
if.
}
...
if,
.
8.
...
if (
< -1)
{ n = 1; }
else
{
if (
> 1) { n = 2; }
else { n = 0; }
65
}
...
,
-
,
.
9.
...
if (
< -1) n = 1;
else
if (
> 1)
n = 2;
else
n = 0;
...
(logical
comparisons),
true (
false (
)
)
bool.
,
==.
C#
>
«
«
»; >= – «
»; != «
».
!=
a
:
<
»;
»; <= –
: a!=b,
,
true,
b.
bool
:
66
-
& –
, and),
(
-
;
|–
, or),
(
-
true,
,
!–
,
o;
, not),
(
-
;
^–
(
),
,
true,
,
.
&, |
^
,
bool.
&&
||,
,
a && b, b
.
true,
,
a||b, b
,
a
.
false,
.
if (
10.
> -1 &&
< 1)
if
-
-1 < x < 1.
if (
11.
< -1 ||
> 1)
if
x < -1
x > 1.
67
:
.
= (
)?
1:
2
12.
int value = (x < 25) ? 5:15
x < 25
true,
.
value
-
5,
15.
–
goto
goto (
)
,
,
,
-
.
:
:
...
goto
...
-
.
C#,
,
-
.
goto,
.
goto
,
-
,
goto,
,
68
-
,
goto
.
if,
, . .
.
switch (
)
.
,
if,
-
switch.
.
switch (
)
{
case
1:
1
break;
case
2:
2
break;
...
default
n
break;
}
-
.
.
69
-
,
,
break.
,
break
,
switch.
,
-
,
default.
.
switch
-
:
switch
(char,
byte,
short
int)
;
;
case
,
switch;
switch
;
break
,
.
13.
int n;
m1: Console.WriteLine("
");
int a = int.Parse(( Console.ReadLine()));
switch (a)
{
case 1:
n = 10;
break;
70
case 2:
case 3:
n = 20;
break;
default:
n = 0;
break;
}
Console.WriteLine("a = " + a +"
n = " + n);
if (a != 0) goto m1;
Console.Read();
,
switch
.
1,
.
n
10
2
.
n
3,
20
-
n
.
0.
,
-
0.
,
switch
switch.
-
.
switch
,
.
switch
-
,
.
71
,
Visual Basic
.
–
,
-
.
.
.
3.1
,
1
(
)
InputB x
,
2
(
)
MsgBox
3
X=A
4
if
72
–
-
.
.
(
)
3.1.
-
.
,
,
.
14.
X , Y
F, . .
Z).
Z.
F = max(X, Y,
:
,
-
.
.
X ,Y
Z
.
X
X > Y
(
c Z.
X > Z
X
Z.
Y,
-
),
X
,
Y.
F
,
–
X >
(
).
73
,
a.
float f;
m1: Console.WriteLine("
X");
float x = float.Parse((Console.ReadLine()));
Console.WriteLine("
Y");
float y = float.Parse((Console.ReadLine()));
Console.WriteLine("
Z");
float z = float.Parse((Console.ReadLine()));
if (x > y)
74
{
if (x > z) f=x;
else f=z;
}
else
{ if(y>z) f=y; else f=z; }
Console.WriteLine('\n' + "
x +
" y= " +
: X= " +
y + " z= " + z +
'\n'+ "
: F= " + f);
Console.WriteLine('\n' + "
" + "
." +
'\n'+ "
Enter.");
string p = Console.ReadLine();
if (p !=
"") goto m1;
14
.
75
-
,c
15.
. 3.1
76
-
.
,
N
(x, y)
,
c
(
.
3.1).
.
.
X
Y,
.
Y (
Y)
.
Y > 0
,
(
Y
,
X
,
N = 4.
(
, . .
Y > 0
X,
),
N
,
= 1,
),
N=2
N = 3.
77
X2 + Y2
X2 + Y2 = R2,
,
< 16,
.
Y > 0,
,
-
.
N = 1,
N = 2.
(
X
0
N = 2,
),
N = 1.
.
X2 + Y2 < 16
(
-
),
X
Y > 0 . .
N = 3.
,
.
int N;
m2:
Console.WriteLine("
"
"+
X ");
float x = float.Parse((Console.ReadLine()));
Console.WriteLine("
"
" +
Y ");
float y = float.Parse((Console.ReadLine()));
if (y > 0)
{
if (x * x + y * y < 16)
{
if (x >= 0)
else
N = 2;
N = 1;
}
78
else
{ N = 3; }
}
else
{ N = 4; }
Console.WriteLine('\t' + "
Console.WriteLine("
+ "
:");
("+ x + ";" + y +
N=" + N);
Console.WriteLine('\n' +"
" + "
."+'\n'+
"
Enter.");
string p = Console.ReadLine();
if (p != "") goto m2;
15
2.
79
")"
.
(
.
1.
F.
.
1)
F=
2)
F=
3)
F=
4)
F=
5)
F=
6)
F=
7)
F=
8)
F=
9)
F=
10)
11)
F=
F=
12) F=
13)
F=
14)
F=
15)
F=
16)
F=
17)
19)
F=
18) F=
1
F=
20)
80
F=
14
15)
21)
F=
22)
F=
23)
F=
24)
F=
25)
F=
26)
F=
27)
F=
28)
F=
29)
F=
30)
F=
2.
N
,
(x,y) c
.
.
1
2
81
-
3
4
5
6
7
8
82
9
10
11
12
13
14
83
15
16
17
18
19
20
84
21
22
23
24
25
26
85
27
28
29
30
86
4
.
1.
,
,
.
.
,
.
for
:
while
-
#
-
(
),
dowhile
.
for
for (
(
)
).
.
,
for
.
-
.
for (
{
1;
;
2)
//
}
.
:
87
1,
-
;
-
,
,
,
,
-
,
,
;
2,
-
,
,
,
-
,
–
.
1.
-
.
,
,
,
.
(
2.
)
,
-
,
,
.
1.
int s, p, n;
s = 0;
p = 1;
for (n = 1; n <= 10; n = n + 1)
{
s = s + n;
p = p * n;
88
}
Console.WriteLine(" s=" + s + " p=" + p);
s
p
.
-
n,
0.
-
n <= 10.
– n = n + 1.
,
1
-
10
,n
1
s
n,
p
n
-
.
-
.
s
,
p
.
.
2.
2.
int s, p, n;
s = 0;
p = 1;
for (n = 1; n <= 10; n ++)
//
n += 1
{
s = s + n;
p = p * n;
Console.WriteLine("n =" + n +"s=" + s + "p="
89
+p);
}
1
n = n +
,
1,
#
n ++,
,
n += 1 .
2,
for
,
.
for
.
,
true.
for(;;) –
,
.
while
while
for,
),
.
,
,
false,
90
-
while
.
for
,
-
.
while (
-
.
)
{
//
}
-
,
,
true.
.
true,
. while (true),
.
3.
,
k
s
[a;b].
.
int a,b,s,k;
Console.WriteLine("
"-
" +
.");
a = int.Parse((Console.ReadLine()));
Console.WriteLine("
"-
b" +
.");
b = int.Parse((Console.ReadLine()));
s = 0;
k = 0;
while ( a <= b)
{
S += a;
//
s = s + a
k++;
//
k = k+1
91
a++;
//
a = a + 1
}
Console.WriteLine('\t' + "
:" +
" s =" + s + " k=" + k + '\n');
a
.
b,
true,
.
.
s,
,
a,
.
k,
,
a
.
false,
,
,
-
.
do-while
do-while
.
while
,
.
92
,
,
,
.
.
.
do
{
//
}
while (
)
true,
,
.
3
,
.
4.
4.
int a, b, s, k;
Console.WriteLine("
" -
"+
");
a =int.Parse((Console.ReadLine()));
Console.WriteLine("
b"+
" -
");
b = int.Parse((Console.ReadLine()));
s = 0;
k = 0;
do
{s += a; k++; a++;}
while (a <=
b);
Console.WriteLine('\t' + "
" s =" + s + " k=" + k + '\n');
93
:" +
break
continue
–
break
continue.
break
,
-
continue
.
,
-
.
if.
.
,
.
,
,
:
-
,
,
;
-
;
;
-
,
;
;
-
,
.
;
.
-
94
5.
1)
-
y
ax
1 ax 2
a
,
(0,5; 1,0; 1,5; 2,0)
x
1
7
0,25).
StreamWriter p = new StreamWriter("rez.txt");
float a,x,y;
p.WriteLine("
");
for (a = 1; a <= 2; a += 0.5f) //
//
{
//
p.WriteLine(" a=" + a);
for (x = 1; x <= 7; x += 0.25f)
//
//
//
{
//
x
y = (float)(a * Math.Cos(x) /
Math.Sqrt(1 + a * x * x));
p.WriteLine("
x=
'\t' + "
" + x
y= "
/*
+
+ y);
x */
}
/*
a */
}
p.Close();
95
x
rez.txt)
(
a=1
x=
1
y= 0,3820514
x=
1,25
y= 0,1969803
x=
1,5
y= 0,03923794
x=
6,75
y= 0,1308689
x=
7
y= 0,1066179
...
a=1,5
x=
1
y= 0,5125757
x=
1,25
y= 0,2586599
x=
1,5
y= 0,05072828
...
x=
6,75
y= 0,1608578
x=
7
y= 0,1310171
x=
1
y= 0,6238874
x=
1,25
y= 0,310508
x=
1,5
y= 0,06032489
a=2
...
,
(
96
1 – 4).
-
,
,
.
.
.
6.
2)
-
y = sin(x)
10-6.
,
30
,
,
-
y = sin(x).
6
double g, pi, x, y, s, a, p, d,
,
;
int n,k;
m1:
Console.WriteLine("
");
g = double.Parse((Console.ReadLine()));
pi = Math.PI;
//
x = g*pi/180;
//
pi
.
Console.WriteLine('\t'+"
"
+'\n');
K = 0;
//
.
S = 0; p = 1;
n = 3; d = 1;
a = x;
//
.
97
while (Math.Abs(a)>= 0.000001)
{
S += a;
//
//
= x*x*x*d;
.
//
.
p = -p*(n-1)*n; //
= p;
.
//
a =
;
.
//
.
d = x*x;
n += 2;
k++;
//
.
Console.WriteLine('\t
+ "
"
+ k + '\n' + " a=" + a + " s=" + s +'\n');
}
y = Math.Sin(x);
//
//
.
Console.WriteLine('\t' + "
:" +'\n'
+ "
.=" + g +\n'
+ "
S =" + s + '\n' + "
- " + k + '\n'
+ "
SIN(X)=" + y + '\n');
Console.WriteLine('\n' + "
+ "
." +'\n'
+ "
Enter.");
string rep = Console.ReadLine();
if (rep !=
"
"") goto m1;
98
6
2.
1.
4.1
y(x)
a
x.
4.1
1.
y (1/ a) exp( ( x / a) 2 )
2.
y xe
3.
y
x/ a
1 / (1 x 2 ) 2
4a 2 x 2
x
a
1,5;
0,1
1; 1,1; 1,2; 1,3
0;
4;
0,2
0,25; 0,5; 0,75; 1,0
0;
2;
0,05
0,1; 0,2; 0,3; 0,4
x ;
x ;
-1,5;
99
4.
y x tga x2 / cos2 a
0;
0,5;
0,02
150; 300; 450; 600
5.
y a xa e
0;
10;
0,25
1; 1,25; ... 2,0
6.
y e
0;
;
/36
0; 0,5; ... 2,0
7.
y ((x a)2/3 (x a)2/3)/ a
-4;
4;
0,2
1; 2; 3; 4
8.
y
0;
2;
0,05
10; 8; 6; 4; 2
9.
y (1 exp( ( x / a)2 )) / a
-2;
2;
0,1
1,25; 1,5; 1,75; 2
-2;
2;
0,05
0,5; 1,0; 1,5; 2,0
1;
7;
0,25
0,5; 0,75; 1,0; 1,25
1;
7;
0,25
0,5; 0,75; 1,0; 1,25
1;
7;
0,25
0,5; 0,75; 1,0; 1,25
1;
7;
0,25
0,5; 0,75; 1,0; 1,25
x2
)
2a
a
0;
2,5;
0,1
0,5; 1,0; 1,5; 2,0
x
)
2a
2a
0;
3;
0,1
0,5; 0,75; 1; 1,25
-3;
3;
18. y Cos 2 (2ax) /(3a)
00;
19. y Sin 2 (ax) /( a 2)
00;
20. y aCos (2 x ) /(a
xa
sinx
x
a
x/a
a
a x
3
2
2
10. y a /(a x )
11. y
4
(a
1) x e
2 ax
3
ax 2
(a
e x
1) x
12. y
13. y
14.
15.
16.
y
3
x
x
arctg
y
x
17. y
21. y
x
ax2
(
3
arctg
y
x2
2
x2
ae
ax
ae
(
2
ax
3
a
a 2e
x
1
/( 2
x3
x
2
4)
a2)
0,2
0,5; 1,0; 1,5, 2,0
3600;
60
1; 1,25; 1,5, 2,0
3600;
60
1; 1,25; 1,5; 2,0
00; 3600;
60
1; 2; 3; 4
0,25
1; 2; 3; 4
-4;
100
4;
3
22. y
ax
23. y
x
24. y
25.
y
0,25
0,5; 1,0; 1,5; 2,0
1;
7;
0,25
0,5; 1,0; 1,5; 2,0
0;
0,8;
0,05
0,5; 1,0; 1,5, 2,0
0;
0,8;
0,05
0,5; 1,0; 1,5; 2,0
2;
12;
0,5
0,5; 1,0; 1,5; 2,0
2;
12;
0,5
0,5; 1,0; 1,5; 2,0
1;
10;
0,5
1; 2; 3; 4
-2;
2;
0,1
1; 2; 3; 4
1;
11;
0,5
1; 2; 3; 4
ax
x 1
xa
a x
ax
1 ax
x a
1 x2
ax
1
ln
7;
x2
a
x 4a
ln
1;
xa
x 1
29. y
30. y
2
a 2e
a
x
x2
27. y ln
x
e
ax
2
26. y ln
28. y
2
2
ax
2
ax
a
x
2.
s(x)
-
y(x)
4.2 .
.
,
10-6.
s(x)
y(x)
4.2
x. C
.
101
4.2
x
1
x 1 x2 1 3 x3 1 3 5 x4
...
S 1
2 24 246 2468
2
S 1
3
x2
2!
x
1!
( 1)
S
x3
3!
n 1
n 1
4
1n
S 1
...
1
n 1
x2
22
x
2
x3
23
2n 3
3n
x 4n
6
x 1 x3 1 3 x5 1 3 5 x7
...
S
1 23 245 2467
0.5;
7
x x3
S
1 3
1/ 3 ;
S
1
n
9
S
n
0 .5
-1; 1; 1.9; y
S
8
y=
2; 1; 0; y
5
x5
5
x 1
sin2 x
/6; 13 /6; 25 /6 ; y
13 5
n! 2
-0.84; 1; 2; y
1; 10; -10;
2 2n 1 2n
x
(2n)!
(x)
...
x7
...
7
x
x
2 x
2 / 2 ; -1; y
arcsin x
1 / 3 ; 1; y
arctgx
2; 20; -15; y (z2 z 1)ex ,
(n 2 1) x n
n! 2 n
1
z x/ 2
2n n
x
sin( n / 4)
n
!
1
/4;
; -5.5 ; y ex sinx
/6;
;
.
10
22n x2n 1
S x
( 1)
(2n)!
n 1
11
x x3
S 2
1 3
12
n
S e
2
x5
5
x7
...
7
4 ; y
x cos 2 x
0.5; 0.9; 0.99; y ln
( x 2) n
1
n!
n 1
1;
102
9;
-15;
y
1 x
1 x
ex
13
2 x 3 x 2 4 x3
S 1
...
1!
2!
3!
1; 9; -11; y
14
2 x 22 x2 23 x3
...
S
1
2
3
1/4; -1/3; 1/2;
15
S 3x 8x 2 ... n(n 2) xn ...
0.2; 0.6; 0.9; y
x(3 x)
(1 x) 3
x 2 ln 2 2
2!
2; 10; -10; y
2x
16
17
18
x ln 2
1!
S
1
S
22 x 2
1
2!
24 x 4
4!
x 3 ln 3 2
...
3!
26 x 6
...
6!
cos(n / 4) n
x
!
n
n 1
S 1
; 5 ;
/6;
; -5 ; y
z
19
20
e z cos z
x/ 2
2
S=1- 2x +3x2 - 4x3+...
0.2; 0.6; 0.9; y 1/(1 x)
0.5; 0.8; 0.99;
x n sin(n / 4)
S
y ln(1 2x)
y cos2x
/6;
.
(1 x) e x
y (x / 2) /(1
n 1
2 x x2 )
.
21
S
cos(x)
1!
1
cos(2 x)
cos(nx)
...
...
2!
n!
.
(2x)2
2!
2n
(2x)4
n (2x)
... ( 1)
...
4!
(2n)!
22
S
23
1
x 1
S
x 1
n 0 2n 1
24
S
/6;
y
- ;
e
cos x
10 ;
cos(sin x )
/6; 13 /6; 25 /6;
y 2(cos2 x 1)
0.5; 0.1; 0.01;
2n 1
y 0.5 ln(x)
2n 1
( x / 2)n
cos(
)
4
n! 2n
2 n1
1
1 3 5 ... (2n 1) x 2n
x
( 1)
2 n n! (2n 1)
n 1
1
n
25
S
26
x 3 x5 x7
x9
S x 2
...
13 35 57 7 9
103
2 /3; 8 /3; 28 /3;
y cos( x / 2 )
0.5; 0.9; 1;
y ln(x
1 x2 )
1/ 3; 1/ 3; 1
y (1 x 2 ) arctg ( x ) ;
27
28
S
3
2
S
n
sin( / 3 n / 2)
n 1
( 1)
n 1
n 1
29
30
*)
S
x 1
3
1
(x 1)n
3n n!
y sin( x / 3)
0.25; 0.45; 0.5;
xn
(1 2 )
n
n
n
0.5; 6.5; 13.5;
y
ln(1 3x 2 x 2 )
2 5 8 ...(3n 4)
( x 1) n
n
-1.331; -0.729; 0;
3 n!
2
3
x
x 2
xn
S 4
(2 2 )
n!
n 1
2; -1; -10; y (1 e )
n
,
y
,
-
.
104
5
.
,
-
.
,
(
),
.
#,
,
.
.
,
[ , b],
, b–
–
-
.
.
,
.
,
,
.
,
-
.
#
:
(value types)
(reference types).
,
.
–
,
.
null –
:
105
-
.
,
«
» (heap).
#
,
.
:
.
,
".
"
#
,
,
.
,
,
:
[]
;
,
,
new:
= new
];
,
-
.
,
.
-
,
.
,
( , C++, Fortran
VBA),
,
)
(
.
.
int
,
array,
int[]
int.
106
-
int[] array = new int[10];
array
,
-
new.
,
int.
.
int[] array;
:
//
//
array = new int[10];
array
//
// 10
int
-
.
#
.
,
0
array
10
9.
.
array
–
,
-
array[0],
array[9].
,
iArray
ray.
1.
//
using System;
namespace Example5
{
class Example5_1
{
107
chAr-
static void Main()
{
int j;
Console.WriteLine("\n\n
iArray");
int[] iArray = new int[10];
for (j = 0; j < 10; j++)
iArray[j] = j * j;
//
//
for (j = 0; j < 10; j++)
//
Console.WriteLine("\n " + j + " "
+ iArray[j]);
Console.WriteLine("\n
chArray
char[] chArray =
{ 'a', 'b', 'c', 'd' };
//
j = -1;
do
{
j++;
Console.WriteLine("\n " +
j + "
" + chArray[j]);
}
while (chArray[j] != 'd');
108
");
//
Console.WriteLine();
Console.Write("\n
");
Console.WriteLine("
iiArray \n");
int[] iiArray = new int[10];
for (j = 0; j < 6; j++)
iiArray[j] = j * j;
iiArray[9] = 81;
foreach (int jj in iiArray)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
Console.Write(" ");
}
}
}
iArray
.
8
.
.
chArray
-
,
-
do-while.
,
foreach.
#
.
chArray.
foreach(char jj in iiArray){...}
109
foreach
iiArray
,
-
char,
.
,
-
,
foreach
,
iiArray.
,
,
,
foreach
.
110
,
,
-
,
-
.
,
–
,
-
.
.
//
int[ ] array1 = new int[5];
//
int[ ] array2 = new int[ ] {1, 3, 5, 7, 9} ;
//
int[ ] array3 = {1, 2, 3, 4, 5, 6} ;
//
//
,
//
int[ ] array4 = new int[10]
{99, 10, 100, 18, 1, 78, 22, 69};
, . .
:
1.
2.
3.
4.
5.
;
;
;
;
111
2.
//
using System;
namespace Example5
{
class Example5_2
{
static void Main()
{
int j;
//
string strValue;
int[] iArray = new int[10];
for (j = 0; j < 10; j++)
{
strValue = Console.ReadLine();
//
iArray[j]= Convert.ToInt32(strValue);
}
for (j = 0; j < 10; j++)
//
Console.WriteLine("\n " + j + " " +
iArray[j]);
}
}
}
112
,
.
iArray[j] = Convert.ToInt32(strValue);
strValue
.
32-
-
,
iArray
(
.
),
,
,
),
.
1,
–
1)
2,
2).
113
-
,
–
-
.
.
,
.
–
(
),
Convert,
ToString,
Parse.
(
)
,
,
-
Parse,
,
–
.
,
.
–
.
Parse,
–
,
ToString.
,
-
Convert,
,
System.
Convert
.
Convert
15
(ToInt16(),ToInt32(), ToInt64(),
..., ToDouble, ToDecimal, ..., ).
object –
-
ToObject
,
114
object.
15
,
.
-
.
3.
//
//
using System;
namespace Example5
{
class Example5_3
{
static void Main()
{
int j, num1, num2;
string str;
double db1, db2;
Random rnd = new Random();
int[] iArray1 = new int[10];
int[] iArray2 = new int[10];
double[] dArray1 = new double[10];
double[] dArray2 = new double[10];
for (j = 0; j < 10; j++)
{
iArray1[j] = rnd.Next(1, 101);
iArray2[j] = 50 - rnd.Next(1,
115
101);
}
for (j = 0; j < 10; j++)
{
num1 = rnd.Next(1, 101);
db1 = Convert.ToDouble(num1);
dArray1[j] = db1 +
Convert.ToDouble(rnd.Next(1,
101)) / 100;
num2 = 50 - rnd.Next(1, 101);
db2 = Convert.ToDouble(num2);
dArray2[j] = db2 –
Convert.ToDouble(rnd.Next(1,
101)) / 100;
}
Console.WriteLine("\n
-------------
-------------------------------");
Console.WriteLine("\n
int
double");
Console.WriteLine("\n
-------------
-------------------------------");
for (j = 0; j < 10; j++)
{
str = string.Format("\n {0, 4:D}
{1, 6:D} {2, 6:D} {3, 8:D}
{4, 8:F2} {5, 8:F2}",
j, iArray1[j],
116
iArray2[j], j, dArray1[j],
dArray2[j]);
Console.WriteLine(str);
}
Console.WriteLine("\n
-------------
-------------------------------");
Console.WriteLine();
}
}
}
.
117
Random.
.
,
.
Random
:
public Random ()
public Random(int seed)
Random,
.
-
seed,
.
iArray1
iArray1
0
iArray2
-50
num1
iArray2,
100,
-
50.
-
num2,
double.
Convert.ToDouble(rnd.Next(1, 101)) / 100;
0.0
,
1.0.
,
dArray1
dArray2
double.
:
-
Random
-
Public virtual int
Next(int upperBound)
,
0
118
upperBound-1
Public virtual int
Next (int lowerBound,
,
lowerBound
int upperBound)
upperBound-1
Public virtual double
NextDouble
,
0,0
(int upperBound)
4.
//
//
using System;
using System.IO;
namespace Example5
{
class Example5_4
{
static void Main()
{
int j;
string strValue;
int[] iArray1 = new int[10];
int[] iArray2 = new int[10];
StreamReader sRead = new
StreamReader("C:\\dat.txt");
StreamWriter sWrite = new
119
1,0
StreamWriter("C:\\res.txt");
for (j = 0; j < 10; j++)
{
strValue = sRead.ReadLine();
iArray1[j] =
Convert.ToInt32(strValue);
iArray2[j] = 10 * iArray1[j];
strValue = string.Format("\n {0,
4:D} {1, 6:D} {2, 6:D}",
j, iArray1[j], iArray2[j]);
Console.WriteLine(strValue);
Console.WriteLine();
sWrite.WriteLine(iArray2[j]);
}
sRead.Close();
sWrite.Close();
}
}
}
.
,
\ (
,
).
,
.
,
,
-
\.
120
, . .
,
-
.
strValue
,
-
,
"\n {0, 4:D} {1, 6:D} {2, 6:D}",
0, 1
2,
-
j, iArray1, iArray2.
4:D
(4),
(D –
mal).
5.
//
121
deci-
//
,
//
15
.
//
//
using System;
namespace Example5
{
class Example5_5
{
static void Main()
{
int j, num;
string str;
string str1 = "
", str2 =
";
string str3 = "
", str4 =
";
double db1, db2;
double sum1 = 0, sum2 = 0,
sum3 = 0, sum4 = 0;
Random rnd = new Random();
int[] iArray1 = new int[15];
int[] iArray2 = new int[15];
double[] dArray1 = new double[15];
double[] dArray2 = new double[15];
for (j = 0; j < 15; j++)
{
122
iArray1[j] = rnd.Next(1, 101);
iArray2[j] = 50 - rnd.Next(1,
101);
sum1 += iArray1[j];
sum2 += iArray2[j];
}
for (j = 0; j < 15; j++)
{
num = rnd.Next(1, 101);
db1 = Convert.ToDouble(num);
dArray1[j] = db1 +
Convert.ToDouble(rnd.Next(1,
101)) / 100;
num = 50 - rnd.Next(1, 101);
db2 = Convert.ToDouble(num);
dArray2[j] = db2 –
Convert.ToDouble(rnd.Next(1,
101)) / 100;
sum3 += dArray1[j];
sum4 += dArray2[j];
}
Console.WriteLine("\n
-------------
-------------------------------------------------");
Console.WriteLine("\n
int
double");
123
Console.WriteLine("\n
-------------
-------------------------------------------------");
for (j = 0; j < 15; j++)
{
str = string.Format("\n {0, 10:D}
{1, 10:D} {2, 10:D} {3, 10:D}
{4, 10:F2} {5, 10:F2}",
j, iArray1[j], iArray2[j],
j, dArray1[j], dArray2[j]);
Console.WriteLine(str);
}
Console.WriteLine("\n
-------------
-------------------------------------------------");
Console.WriteLine("\n {0, 10} {1, 10}
{2, 10} {3, 10}
{4, 10:F2} {5, 10:F2}",
str1, sum1, sum2,
str2, sum3, sum4);
Console.WriteLine("\n {0, 10}
{1, 10:F2}
{2, 10:F2} {3, 10}
{4, 10:F2} {5, 10:F2}",
str3, sum1 / 15, sum2 /
15, str4, sum3 /
15, sum4 / 15);
124
Console.WriteLine();
}
}
}
int iArray1, iArray2,
dArray1, dArray2
double
.
-
125
– sum1
sum2.
.
.
sum1
-
sum2
iArray1, iArray2.
-
dArray1, dArray2 – sum3
sum4.
,
int
.
D,
double –
F (fixed point).
6.
//
//
,
10
//
//
using System;
namespace Example5
{
class Example5_6
{
static void Main()
{
int j, num, sum = 0;
Random rnd = new Random();
int[] iArray = new int[10];
126
-
for (j = 0; j < 10; j++)
{
iArray[j] = rnd.Next(1, 101);
}
for (j = 0; j < 10; j++)
{
num = Convert.ToInt32(iArray[j]
% 2);
if (num == 0) sum += iArray[j];
}
foreach (int jj in iArray)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
Console.WriteLine("\n
= " + sum);
Console.WriteLine();
Console.Write(" ");
}
}
}
,
,
-
num = Convert.ToInt32(iArray[j] % 2);
if (num == 0) sum += iArray[j];
2
iArray[j] % 2,
127
-
num == 0 ,
.
iArray[j]
sum.
7.
//
//
//
,
20
//
//
using System;
namespace Example5
{
class Example5_7
{
static void Main()
{
int j, jnum = 0;
Random rnd = new Random();
int[] iArray = new int[20];
for (j = 0; j < 20; j++)
{
iArray[j] = 50 - rnd.Next(1,
128
101);
}
for (j = 0; j < 20; j++)
{
if (iArray[j] > 0) jnum += 1;
if (jnum == 2) break;
}
foreach (int jj in iArray)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
Console.WriteLine("\n
= " + j);
Console.WriteLine("\n iArray[" +
j + "] = " + iArray[j]);
jnum = 0;
for (j = 0; j < 20; j++)
{
if (iArray[j] < 0) jnum += 1;
if (jnum == 3) break;
}
Console.WriteLine("\n
= " + j);
Console.WriteLine("\n iArray[" +
j + "] = " + iArray[j]);
Console.WriteLine();
Console.Write(" ");
}
129
}
}
iArray
jnum
.
-
,
jnum == 2
.
true
break
.
.
8.
//
N.
//
,
//
//
,
-
.
//
.
//
//
130
using System;
namespace Example5
{
class Example5_8
{
static void Main()
{
int jnum = 0, N = 20;
int jAA = 0, jBB = 0;
int j, k, temp;
Random rnd = new Random();
int[] iArray = new int[N];
int[] jA = new int[N];
int[] jB = new int[N];
for (j = 0; j < N; j++)
{
iArray[j] = rnd.Next(1, 101);
}
Console.WriteLine("\n
\n\n");
foreach (int jj in iArray)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
for (j = 0; j < N; j++)
131
{
jnum = iArray[j] / 2;
iArray[j] =
Convert.ToInt32(iArray[j]);
if (iArray[j] == jnum * 2)
{
jA[jAA] = iArray[j];
jAA += 1;
}
else
{
jB[jBB] = iArray[j];
jBB += 1;
}
}
Console.WriteLine("\n
A[]
\n\n");
foreach (int jj in jA)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
Console.WriteLine("\n
\n\n");
foreach (int jj in jB)
{ Console.Write(" " + jj); }
132
B[]
Console.WriteLine("\n\n");
//
jAA -= 1;
for (k = 0; k < jAA; k++)
{
for (j = 0; j < jAA; j++)
{
if (jA[j + 1] < jA[j])
{
temp = jA[j];
jA[j] = jA[j + 1];
jA[j + 1] = temp;
}
}
}
//
B
jBB -= 1;
for (k = 0; k < jBB; k++)
{
for (j = 0; j < jBB; j++)
{
if (jB[j + 1] < jB[j])
{
temp = jB[j];
133
jB[j] = jB[j + 1];
jB[j + 1] = temp;
}
}
}
Console.WriteLine("\n
A[] \n\n");
foreach (int jj in jA)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
Console.WriteLine("\n
B[] \n\n");
foreach (int jj in jB)
{ Console.Write(" " + jj); }
Console.WriteLine("\n\n");
}
}
}
,
-
.
,
–
.
jA –
jA –
.
134
,
-
jA
.
j
:
j
j+1,
temp = jB[j];
jB[j] = jB[j + 1];
jB[j + 1] = temp;
jA
.
135
j
2.
.
-
,
.
N.
1.
,
.
N.
2.
-
N/2,
,
.
-
.
3.
,
.
4.
,
,
.
N
5.
.
6.
,
10-
.
7.
,
,
.
136
20-
-
8.
,
20-
.
9.
,
,
20-
.
10.
,
,
20-
-
.
11.
D.
.
12.
,
10-
-
,
.
,
.
13.
,
20-
,
.
(15)
14.
.
15.
,
,
16.
.
,
50-
,
.
17.
:
,
–
–
137
.
18.
,
10-
19.
.
.
10-
,
,
.
20.
,
,
107
-
,
.
7
.
21.
.
,
C.
–
22.
(
)
-
23.
(
)
:
24.
(
)
:
25.
(
)
26.
(
27.
:
)
(
)
28.
(
29.
(
:
)
.
138
-
:
)
,
:
:
-
30.
(
)
:
.
139
6
C++
;
0
.
,
,
.
#
C++
.
-
#
-
.
"
0
".
,
-
,
-
,
.
C++ "
"
,
,
.
-
,
-
-
.
#,
,
.
-
.
.
.
140
-
,
,
integer
int[,]
–
.
10x15:
table = new int[10, 15];
.
,
-
.
new,
:
int[10, 15]
10×15.
-
,
.
myArray
(3,5)
, . .
-
10:
myArray [3, 5] = 10;
#
.
.
[,...,]
...
= new
N];
141
[
1,
2,
,
4x10x3.
int [,,]
multiArray = new int[4, 10, 3];
multiArray,
-
(2,4,1)
100:
multidim[2, 4, 1] = 100;
,
3x3x3,
,
.
.
//
//
-
3x3x3.
using System;
class Example
{
static void Main()
{
int [,,] m = new int[3,-3,3];
int sum = 0;
int n = 1;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
142
for (int k = 0; k < 3; k++)
m[i, j, k] = n++;
sum = m[0, 0, 0] +
m[l, 1, 1] + m[2, 2, 2];
Console.WriteLine("
: "
+ sum);
}
}
:
:
42
.
:
[,]
=
{
{val, val, val, ..., val},
{val, val, val, ..., val},
{val, val, val, ..., val}
};
val
,
–
.
-
143
,
–
. .
,
.
.
1.
//
//
using System;
namespace Example6
{
class Example6_1
{
static void Main()
{
int i, j;
string strValue;
int[,] iArray = new int[3, 4];
int[,] jArray = new int[3, 4];
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 4; ++j)
{
//
144
strValue = Console.ReadLine();
iArray[i, j] =
Convert.ToInt32(strValue);
}
}
//
iArray
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 4; ++j)
{
Console.Write(" iArray[" + i + ",
" + j + "] =
" + iArray[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
//
jArray
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 4; ++j)
{
jArray[i, j] = iArray[i, j] * 10;
Console.Write(" jArray[" + i + ",
" + j + "] = " + jArray[i, j]);
}
Console.WriteLine();
}
145
Console.WriteLine();
}
}
}
,
-
ReadLine.
,
,
,
.
-
ReadLine.
-
ToInt32
int
iArray[i, j].
jArray
jArray[i, j] = iArray[i, j] * 10;
.
146
-
StreamReader.
StreamReader
-
.
StreamReader(string
),
–
,
.
,
\,
-
.
,
\(
).
2.
//
//
//
using System;
using System.IO;
namespace Example6
{
class Example6_2
{
static void Main()
{
int i, j;
string strValue;
int[,] iArray1 = new int[3, 4];
int[,] iArray2 = new int[3, 4];
147
StreamReader sRead = new
StreamReader("C:\\C#\\dat.txt");
StreamWriter sWrite = new
StreamWriter("C:\\C#\\res.txt");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
strValue = sRead.ReadLine();
iArray1[i, j] =
Convert.ToInt32(strValue);
iArray2[i, j] = iArray1[i, j] *
100;
strValue = string.Format("\n {0,
4:D} {1, 4:D} {2, 6:D} {3, 6:D}",
i, j, iArray1[i, j], iArray2[i,
j]);
Console.WriteLine(strValue);
Console.WriteLine();
}
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
sWrite.WriteLine(iArray2[i, j]);
}
148
}
sWrite.Close();
}
}
}
Console (Example6_1)
,
StreamReader
StreamWriter (Example6_2).
-
.
iArray1
,
int,
–
-
double
Sin(x).
strValue,
-
iArray1
.
iArray2[i, j] = iArray1[i, j] * 100;
iArray2
-
res3.txt.
Array –
,
-
System.
.
Length
,
.
149
int
Copy (Array source, Array dest, count)
count,
,
source
dest,
iArray1
.
.
3.
//
//
.
//
//
150
-
using System;
using System.IO;
namespace Example6
{
class Example6_3
{
static void Main()
{
int i, j, num;
double x = 0;
string strValue;
double[,] iArray1 = new double[10, 3];
double[,] iArray2 = new double[10, 3];
Random rnd = new Random();
StreamWriter sWrite = new
StreamWriter("C:\\C#\\res3.txt");
Console.WriteLine("\n ---------------------------------------");
for (i = 0; i < 10; i++)
{
num = rnd.Next(1, 51);
iArray1[i, 0] =
Convert.ToDouble(num);
num = (rnd.Next(1, 101) - 50) / 10;
iArray1[i, 1] =
Convert.ToDouble(num);
iArray1[i, 2] = Math.Sin(x);
151
x = x + 0.314159;
strValue = string.Format("\n {0, 4:D}
{1, 10:F0} {2, 10:F2} {3, 10:F2}", i,
iArray1[i, 0], iArray1[i, 1],
iArray1[i, 2]);
Console.WriteLine(strValue);
}
Console.WriteLine("\n ---------------------------------------");
for (i = 0; i < 10; i++)
{
for (j = 0; j < 3; j++)
{
iArray2[i, j] = iArray1[i, j] *
100;
sWrite.WriteLine(iArray2[i, j]);
}
}
num = iArray2.Length;
Array.Copy(iArray2, iArray1, num);
for (i = 0; i < 10; i++)
{
strValue = string.Format("\n {0, 4:D}
{1, 10:F0} {2, 10:F2} {3, 10:F2}", i,
iArray2[i, 0], iArray2[i, 1],
iArray2[i, 2]);
Console.WriteLine(strValue);
152
}
Console.WriteLine("\n ---------------------------------------");
sWrite.Close();
}
}
}
153
Example6_4
,
-
.
,
.
,
,
–
.
4.
//
.
//
//
using System;
using System.IO;
namespace Example6
{
class Example6_4
{
static void Main()
{
int i, j;
int num, sum = 0;
int[,] iArray = new int[5, 6];
int[ ] iA = new int[6];
Random rnd = new Random();
string strValue = "\n ------------------------------";
Console.Write("\n
//
154
");
for (j = 0; j < 6; j++)
Console.Write("{0, 5}", j);
Console.WriteLine(strValue);
//
;
//
for (i = 0; i < 5; i++)
{
for (j = 0; j < 6; j++)
{
num = rnd.Next(1, 101);
iArray[i, j] =
Convert.ToInt32(num);
iA[j] = iArray[i, j];
sum = sum + iArray[i, j];
}
}
//
for (i = 0; i < 5; i++)
{
//
Console.Write("\n " + i);
for (j = 0; j < 6; j++)
{
//
Console.Write("{0, 5}",
iArray[i, j]);
}
155
}
Console.WriteLine(strValue);
Console.WriteLine();
Console.WriteLine("
:
" + sum);
Console.WriteLine("
:
" + sum / 30);
Console.WriteLine();
}
}
}
A,
.
.
,
,
,
,
–
156
.
-
5.
//
A(M, N)
//
.
//
2
- 2
using System;
namespace Example6
{
class Example6_5
{
static void Main()
{
int M = 6, N = 8;
int i, j, temp;
int[,] iArray1 = new int[M, N];
int[,] iArray2 = new int[M, N];
int[ ] iArray3 = new int[N];
Random rnd = new Random();
string strValue = "\n ----------------------------------------";
Console.Write("\n
");
Console.WriteLine("\n
");
Console.WriteLine(strValue);
//
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
157
:
{
temp = rnd.Next(1, 101);
iArray1[i, j] =
Convert.ToInt32(temp);
iArray2[i, j] =
Convert.ToInt32(temp);
iArray3[j] = iArray1[i, j];
}
foreach (int jj in iArray3)
{
Console.Write("{0, 5}", jj);
}
Console.Write("\n");
}
Console.WriteLine(strValue);
Console.WriteLine("\n
: ");
Console.WriteLine(strValue);
for (j = 0; j < N; j++)
{
temp = iArray2[2, j];
iArray2[2, j] = iArray2[M - 2, j];
iArray2[M - 1, j] = temp;
}
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
158
{
iArray3[j] = iArray2[i, j];
}
foreach (int jj in iArray3)
{
Console.Write("{0, 5}", jj);
}
Console.Write("\n");
}
Console.WriteLine(strValue);
Console.WriteLine();
Console.WriteLine();
}
}
}
159
6.
//
A(5, 6)
//
.
//
,
//
//
,
//
using System;
namespace Example6
{
class Example6_6
{
static void Main()
{
int im = 0, jm = 0, i, j;
int num, sum = 0;
int max = -100, min = 100;
int[,] iArray = new int[5, 6];
int[ ] iA = new int[6];
Random rnd = new Random();
string strValue = "\n ------------------------------";
Console.Write("\n
");
//
for (j = 0; j < 6; j++)
Console.Write("{0, 5}", j);
Console.WriteLine(strValue);
160
//
;
for (i = 0; i < 5; i++)
{
sum = 0;
for (j = 0; j < 6; j++)
{
num = rnd.Next(1, 101);
iArray[i, j] =
Convert.ToInt32(num);
iA[j] = iArray[i, j];
sum = sum + iArray[i, j];
}
if (sum > max)
{
max = sum;
im = i;
}
}
for (j = 0; j < 5; j++)
{
if (iArray[im, j] < min)
{
min = iArray[im, j];
jm = j;
}
}
//
161
for (i = 0; i < 5; i++)
{
//
Console.Write("\n " + i);
for (j = 0; j < 6; j++)
{
//
Console.Write("{0, 5}",
iArray[i, j]);
}
}
Console.WriteLine(strValue);
Console.WriteLine();
Console.WriteLine("\n i = " + im);
Console.WriteLine("\n j = " + jm);
Console.WriteLine();
}
}
}
j.
i
.
.
if (sum > max)
162
sum
-
.
-
{
max = sum;
im = i;
}
im.
-
if (iArray[im, j] < min)
{
min = iArray[im, j];
jm = j;
}
jm
.
.
163
k = i * j.
.
if (k < 10) Console.Write("
else
");
Console.Write(" ");
k < 10
–
,
.
,
.
7.
//
//
.
//
using System;
namespace Example6
{
class Example6_7
{
static void Main()
{
int i, j, k, m = 0;
for (i = 1; i < 10; i++)
{
Console.WriteLine("\n");
for (j = 1; j < 10; j++)
{
k = i * j;
164
m++;
if (k < 10) Console.Write("
else
");
Console.Write(" ");
Console.Write(k);
}
}
Console.WriteLine("\n\n
: "
+ m);
Console.WriteLine("\n");
}
}
}
.
break
-
continue.
165
break
.
continue
,
.
8.
//
(
)
.
//
//
.
//
(
)
.
using System;
namespace Example6
{
class Example6_8
{
static void Main()
{
//
int i, j, k, m = 0;
for (i = 1; i < 10; i++)
{
Console.WriteLine("\n");
for (j = 1; j < 10; j++)
{
k = i * j;
if (j > 10 - i) break;
m++;
if (k < 10) Console.Write("
166
");
else Console.Write(" ");
Console.Write(k);
}
}
Console.WriteLine("\n\n
: "
+ m);
Console.WriteLine("\n");
m = 0;
for (i = 1; i < 10; i++)
{
Console.WriteLine("\n");
for (j = 1; j < 10; j++)
{
k = i * j;
if (k < i * (10 - i))
Console.Write("
");
else
{
if (k < 10) Console.Write
("
" + k);
else Console.Write(" " + k);
m++;
}
}
}
Console.WriteLine("\n\n
+ m);
167
: "
Console.WriteLine("\n");
}
}
}
,
-
.
,
168
-
.
#
-
,
.
,
-
.
,
.
-
,
.
,
:
[][]
= new
[
][];
.
,
.
,
.
,
.
,
jagged,
(2,1),
10:
jagged[2][1]
= 10;
.
169
-
.
,
C#
.
9.
//
//
.
using System;
namespace Example6
{
class Example6_9
{
static void Main()
{
int j, max = 0;
int[]
= new int[5];
for (j = 0; j < 5; j++)
{
[j] = j + 2;
if (
[j] > max) max =
[j];
}
//
,
//
//
int
0 = 5;
int
1 = max;
int
2 = Convert.ToInt32((4 * max
170
- 1) / 3);
int[]
= {
0,
1,
2 };
int[ ][ ]
= new int[3][ ];
[0] = new int[
[0]];
[1] = new int[
[1]];
[2] = new int[
[2]];
Console.WriteLine();
Console.Write("
for (j = 0; j <
");
2; j++)
Console.Write("{0,5}", j);
Console.WriteLine("\n\t\t ---------------------------------- ");
Console.Write("
for (j = 0; j <
[0][5]");
0; j++)
[0][j] = j + 1;
foreach (int jj in
[0])
Console.Write("{0,5}", jj);
Console.WriteLine();
Console.Write("
for (j = 0; j <
[1][6]");
1; j++)
[1][j] = j + 11;
foreach (int jj in
[1])
Console.Write("{0,5}", jj);
Console.WriteLine();
Console.Write("
for (j = 0; j <
171
[2][7]");
2; j++)
[2][j] = j + 111;
foreach (int jj in
[2])
Console.Write("{0,5}", jj);
Console.WriteLine("\n\t\t ---------------------------------- ");
Console.WriteLine();
}
}
}
,
.
,
,
,
,
.
,
-
,
.
,
,
.
.
int[ ][,] jArray = new int[5][,];
172
2.
.
-
,
.
1.
5-
6-
.
2.
A(5,6)
.
,
(4, 6)
3.
.
(4).
,
.
(20, 30)
4.
-
.
(30).
(4, 5),
5.
.
D(5).
,
.
173
6.
(6, 4),
.
2-
7.
4-
-
.
(4, 5),
.
-
.
(5,5)
8.
.
9.
,
(4, 4).
10.
(4,4),
-
.
(5, 6)
11.
(30)
,
-
.
12.
100.
13.
.
A(5, 10)
14.
-
(10, 4).
N×N.
15.
.
174
N×N.
16.
.
N×N.
17.
.
18.
N×N,
,
,
,
-
.
N×N
19.
,
-
,
.
.
20.
N×M
-
,
-
. .
16.
21.
4×4
.
N×M
22.
.
N×N.
23.
-
.
24.
,
N×N.
.
N×N
25.
90°,
.
175
-
N×N
26.
-
,
,
,
.
N×N
27.
.
,
28.
.
,
.
-
,
29.
,
30.
176
7
1.
,
,
-
,
,
.
-
.
,
.
,
,
,
,
.
»
,
,
,
.
–
,
.
,
,
,
,
Windows.
New
(new)
.
177
:
1.
new –
.
.
.
)
. 7.1.
178
-
2.
3.
public –
protected
4.
5.
internal –
protected internal –
–
.
(
(
6.
)
)
private –
.
,
7.
abstract
–
.
.
8.
sealed
–
.
.
9.
static –
.
2.0.
2 – 6
.
,
.
,
,
.
,
:
,
–
-
,
,
,
,
,–
,
,
179
.
,
:
,
-
,
.
:
//
(int)
public int Add (int first, int second)
{
int Result;
Result = first + second;
Return result;
}
public void myVoidMethod ()
// void –
{
MessageBox.Show ("
");
}
,
,
(
)
.
.
,
.
,
.
//
Rotate
Rotate (45, "Degrees");
Main –
,
-
.
180
,
.
–
.
;
.
–
,
.
,
.
public void DisplayName (string name, byte age)
{
Console.WriteLine ("Hello " + name + ". You are "
+ age.ToString () +"years old.");
}
.
String,
:
name,
Byte.
, age, –
,
.
:
2
C
4,5 e x
8,5 sin( x)
ex
fn
D
8 ex
4
1
sin( x 4 )
x3
double
public double fn (a as double, x as double, z double)
{
return (a exp(x) + z
sin(x));
}
181
...
c = fnc ( a, x x, 0. ) / fnc ( 1., x, 8.5 )
b = -1.
d = 1/( fnc (8., x^4, b) + x ^ 3)
...
fnc
,
, z
d.
D(5).
1.
vect
-
,
,
k.
public
)
using System;
namespace ConsoleApplication1
{
class Program
{
class vect
//
{
double[] a; //
int n;
//
public vect(int n)
//
{
this.a = new double[n];
this.n = n;
}
182
vect
public int vv()
//
,
//
{
for (int i = 0; i < n; i++)
{
string buf;
//
buf = Console.ReadLine();
//
a[i] = Convert.ToDouble(buf);
//
}
return (0);
}
public int vyv()
//
//
{
for (int i = 0; i < n; i++)
Console.WriteLine("a["+i+"]="
a[i]);
return (0);
}
public int perest(int k)
//
1
183
+
// k-
.
{
//
; 0
//
-1,
-
int kl = 0;
//
if ( k >= n ) kl = -1;
else
{
//
int cnt = 0;
//
int pos = -1;
double tmp;
//
while ( cnt < k )
{
pos++;
if (a[pos] < 0) cnt++;
}
//
tmp = a[pos];
//
a[pos] = a[0];
a[0] = tmp;
kl = 0;
}
return kl;
}
184
//
static void Main()
{
//
vect d = new vect(5);
d.vv();
//
d.vyv();
//
//
d.perest(2);
//
d.vyv();
//
//
}
}
}
}
2.
D(3,3).
.
myprog.
.
.
using System;
//
namespace ConsoleApplication3
{
class myprog
185
.
a
{
static void Main()
{
//
double[,] d = new double[3,3];
double[,] dt = new double[3, 3];
double[,] ddt = new double[3, 3];
//
d c
int i; int j; //
,
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
d[i, j] =
Convert.ToDouble(Console.ReadLine());
}
//
transp(d, 3, dt);
//
//
dt
d
mt_q_mult(dt, d,ddt,3);
}
//
static void transp(double[,] mtr,
int p, double[,] mtrt)
// double[,] mtr //
186
{
int i; int j;
for (i = 0; i < p; i++)
{
for (j = 0; j < p; j++)
mtrt[j, i] = mtr[i, j];
}
}
//
static void mt_q_mult(double[,] m_a,
double[,] m_b, double[,] m_r, int p)
// m_r=m_a * m_b , int p
{
int i; int j; int k; double mel;
for (i = 0; i < p; i++) //
m_a
{
//
m_b
for (j = 0; j < p; j++)
{
mel=0;
//
m_a
m_b
for (k = 0; k < p; k++)
mel=mel+m_a[i,k]*m_b[k,j];
m_r[i,j]=mel;
}
}
}
187
}
}
2.
,
.
.
(4, 4)
1.
(4, 4).
Y,
–
,
,Y–
(4, 4)
2.
Z =
.
(4, 4).
+
,
–
,
,Y –
.
(4, 4)
3.
B(3, 3)
C(4)
D(3).
.
.
(4,4)
4.
D(3,3).
-
.
188
(3,
5.
3)
(3,
3).
–
,
=
.
(4,
6.
4)
D(3,
.
3).
.
,
.
,
(6)
7.
.
D(10).
.
2
8.
DX2 + FX + E = 0
+ B
+
= 0;
ZX2 + YX + S = 0.
.
(0.052; 0.9; 0.15; 0.84; 0.67)
9.
(0.948; 0.1; 0.33; 0.16; 0.85).
,
–
,
.
.
A(4, 4)
10.
B(3, 3).
.
A, B, C, D
11.
.
ABC,
ABD, ACD.
189
12.
.
.
(4, 4)
13.
(3, 3).
.
(4,
14.
4)
(4,
Z =
– Y,
4).
–
;Y–
,
.
X, Y, Z.
15.
n
S
Ci
Ci Di ,
D,
Di –
i 1
=
+ Y;
(4, 4)
16.
D =
- Z
D(3, 3).
,
.
(5),
17.
(10), D(15).
.
18.
.
R
.
19.
.
,
,
–
.
.
190
Y(4, 4)
20.
Z(8, 8).
,
.
21.
.
.
2×2, 3×3, 4×4.
22.
.
23.
.
.
24.
.
,
.
-
25.
)2 + (
-
)2 + (
- b)2 = r2
- d)2 = R2
.
,
.
(5),
26.
(10),
2
+ d
(15).
+ r = 0,
, d –
–
,r–
.
(5)
27.
Y(7).
,
.
(5)
.
28.
.
191
(10)
(4,4),
29.
(6,6).
,
.
F(2,2)
30.
(2,2)
.
.
192
1.
.
.,
.
.,
.
.,
.
.
:
.
2.
.
.,
.;
.
«
», 2007,
.
-
:
.
», 2010, 85 .
3.
. .,
. .
Basic for Application:
2009, 90 .
4.
. . C#
.
, 2007, 432 .
5.
.
», 2010, – 992.
193
144 .
.
.;
.;
C# 3.0.
«
.;
Visual
»,
.
........................................................................................... 3
................................................. 20
1....................................................... 22
2....................................................... 41
3....................................................... 58
4....................................................... 87
5..................................................... 105
6..................................................... 140
7..................................................... 177
.................................................................................. 193
194
C#
»
2011 .
27.09.11.
«
60 90 1/16.
».
100
.
.
, .
195
. . 12.1
.119-11.
«
107023, .
.
»
., 38
80
2
Скачать