Lab03-BasicC# partII V2 - Kasetsart University

?? ?o..............................................................................??a?i?i?......................................???...............

Lab 3 ? Basic of C# (partII)

1.

1 2 3 4 5 6

()

++(x),--(x) *, /, % +, -

=, +=, -=, *=, /=, %= (x)++, (x)--

1.1 : SharpDevelop

using System; class Class1 {

static void Main() {

double x = 3.0, y = 2.0; int a = 10, b = 2;

Console.WriteLine( (A) ); } }

(A)

1. x+a*b

23

x+(a*b)

2. b*a/b

3. y/x%b

4. a-y%x

5. ++y%x-1

6. a+b%b

7. x/y*++b

8. x/y*b++

10. x+y-x*y%x

12. (a+b)/b%a

Lab 3 : Basic of C# (partII)

(1)

204111 : Computer & Programming

2. Math.Class

2.1 : SharpDevelop

using System; class Class1 {

static void Main() {

Console.WriteLine("Constant"); Console.WriteLine("Math.PI = {0}",Math.PI); Console.WriteLine("Math.E = {0}",Math.E); Console.ReadLine(); } }

Math.PI Math.E

Math.PI

Math.E

2.2 : SharpDevelop

1 using System;

2 class Class1

3 {

4

static void Main()

5

{

6

Console.Write("Input = ");

7

double x = double.Parse(Console.ReadLine());

8

Console.WriteLine("Abs(x) = {0}",Math.Abs(x));

9

Console.WriteLine("Ceiling(x) = {0}",Math.Ceiling(x));

10

Console.WriteLine("Floor(x) = {0}",Math.Floor(x));

11

Console.WriteLine("Round(x) = {0}",Math.Round(x));

12

Console.ReadLine();

13

}

14 }

input

Input

-4.7 -4.6 -4.5 -4.4 -4.3 5.3 5.4 5.5 5.6 5.7

Math.Abs(x)

Math.Ceiling(x)

Math.Floor(x)

Math.Round(x)

Lab 3 : Basic of C# (partII)

(2)

204111 : Computer & Programming

Math.Abs(x)

Math.Ceiling(x)

Math.Floor(x)

Math.Round(x)

8 ? 11 2.2

Console.WriteLine("Sqrt(x) = {0}",Math.Sqrt(x)); Console.WriteLine("Log(x) = {0}",Math.Log(x)); Console.WriteLine("Log10(x) = {0}",Math.Log10(x));

input

Input

-10 -1 1 2 3 4 9 10

Math.Sqrt(x)

Math.Log(x)

Math.Log10(x)

Math.Sqrt(x)

Math.Log(x)

Math.Log10(x)

100 10,000

2.3 : SharpDevelop

using System; class Class1 {

static void Main() {

Console.Write("Input x = "); double x = double.Parse(Console.ReadLine()); Console.Write("Input y = "); double y = double.Parse(Console.ReadLine()); Console.WriteLine("Pow(x,y) = {0}",Math.Pow(x,y)); Console.WriteLine("Max(x,y) = {0}",Math.Max(x,y)); Console.WriteLine("Min(x,y) = {0}",Math.Min(x,y)); Console.ReadLine(); } }

input

Lab 3 : Basic of C# (partII)

(3)

204111 : Computer & Programming

Input (x, y)

(6, 3)

(2, 5)

(5, 2) (10, -1) (-5, -2)

Math.Pow(x,y)

Math.Max(x,y)

Math.Min(x,y)

Math.Pow(x,y)

Math.Max(x,y)

Math.Min(x,y)

(4, 0.5)

2.4 : SharpDevelop

1 using System;

2 class Class1

3 {

4

static void Main()

5 {

6

Console.WriteLine("sin(A) = {0}",Math.Sin( (1) ));

7

Console.WriteLine("cos(A) = {0}",Math.Cos( (1) ));

8

Console.WriteLine("tan(A) = {0}",Math.Tan( (1) ));

9

Console.ReadLine();

10 }

11 }

(1) 6, 7 8

(1)

0 Math.PI/6 Math.PI/4 Math.PI/3

sin(A) =

cos(A) =

tan(A) =

2.5 : C#

C#

y

x +z

| (x+2)*log5 |

3 cos

16

Lab 3 : Basic of C# (partII)

(4)

204111 : Computer & Programming

3. input

2 Console.Read() Console.ReadLine() Console.Read() Console.Read() ASCII Code

Console.ReadLine() (string)

3.1 : SharpDevelop Method Main

1 static void Main()

2 {

3

int x; char c;

4

Console.Write("Please input something : ");

5

x = Console.Read();

6

Console.WriteLine(x);

7

c = Convert.ToChar(x);

8

Console.WriteLine(c);

9

Console.ReadLine();

10

Console.ReadLine();

11 }

5 7

5

x = Console.Read();

7

c = Convert.ToChar(x);

Console.ReadLine() (string)

static void Main() {

string input; Console.Write("Please input something : "); input = Console.ReadLine(); Console.WriteLine(input); Console.ReadLine(); }

4. output

output 2 Console.Write() Console.WriteLine() Console.Write() Console.WriteLine()

output

1 Console.Write() Console.WriteLine()

Console.Write("Hello!!");

Lab 3 : Basic of C# (partII)

(5)

204111 : Computer & Programming

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download