introduction to digital logic - weerayuth...

37
พื นฐานการเขียนโปรแกรม วีระยุทธ คุณรัตนสิริ

Upload: others

Post on 05-Feb-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

พ้ืนฐานการเขียนโปรแกรมวี ระยุทธ คุณ รัตนสิ ริ

Page 2: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ภาษา C# รองรับการโปรแกรมเชิงวัตถุ (Object-Oriented Programming –

OOP)

พัฒนาโดยบริษัทไมโครซอฟต์ เพื่อเป็นส่วนหนึ่งของสถาปัตยกรรม .NET

มีโครงสร้างคล้ายกับภาษา C, C++ และ Java

ท างานร่วมกับภาษาอื่นในสถาปัตยกรรม .NET ได้ง่าย

Page 3: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การสร้างและคอมไพล์โปรแกรม◦ ใช้โปรแกรมประเภท Integrated Development Environment

(IDE) ที่รวม Text Editor และจัดการเรื่องการคอมไพล์ให้◦ เช่น Microsoft Visual C#

Page 4: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ประเภทของแอพลิเคชันConsole Application◦ แสดงผลในรูปตัวอักษร◦ รับข้อมูลผ่านแป้นพิมพ์เพียงอย่างเดียว

Windows Form Application◦ ใช้ได้ทั้งแป้นพิมพ์และเมาส์◦ แสดงผลในรูปกราฟิคส์

Page 5: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

พื้นฐานการเขียนโปรแกรมด้วย C#

Page 6: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

โปรแกรมภาษา C#พิจารณาโปรแกรมต่อไปนี้

namespace Hello {

class HelloClass {

static void Main () {

System.Console.WriteLine("Hello World!");

System.Console.ReadLine();

}

}

}

Page 7: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

โปรแกรมภาษา C# ตัวอักษรเล็ก / ใหญ่เป็นคนละตัวกัน (Case Sensitive)

ค าสั่งทุกค าสั่งต้องปิดท้ายด้วยเครื่องหมายเซมิโคลอน (;)

จ านวนช่องว่าง (ทั้งแนวต้ังแนวนอน) ไม่มีผลต่อการท างาน

ใช้เครื่องหมายปีกกา {} จับกลุ่มค าสั่ง

ข้อความที่อยู่ระหว่าง /* */ หรือหลัง // ถือเป็นหมายเหตุ (Comment) ซึ่งไม่มีผลต่อการท างานของโปรแกรม

Page 8: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

โครงสร้างของโปรแกรมจุดเริ่มต้นของโปรแกรมจะอยู่ที:่

◦ เรียกว่าเมท็อด Main◦ เมท็อดต้องอยู่ภายใต้คลาส (class)◦ คลาสอาจอยู่ภายใต้เนมสเปส (namespace) หรือไม่ก็ได้

static void Main ()

{

... starting point ...

}

Page 9: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

โครงสร้างของโปรแกรมคลาสเปรียบเสมือนกล่องบรรจุเมท็อดหลาย ๆ เมท็อด

เนมสเปสเปรียบเสมือนกล่องบรรจุคลาสหลาย ๆ คลาส◦ เนมสเปสอาจอยู่ภายใต้เนมสเปสอื่นได้อีก

โปรแกรมหนึ่ง ๆ อาจประกอบด้วยหลายเนมสเปส หรืออาจไม่อยู่ในเนมสเปสใด ๆ เลยก็ได้

method1

method2

Namespace

Class

Page 10: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

โครงสร้างของโปรแกรม

ส าหรับโปรแกรมอย่างง่าย◦ โปรแกรมประกอบด้วยคลาสเพียงคลาสเดยีว◦ โปรแกรมอาจประกอบดว้ยเมท็อด Main เพียงเมท็อดเดียว

namespace HelloW {

class HelloWClass {

static void Main () {

System.Console.WriteLine("Hello World!");

System.Console.ReadLine();

}

}

}

Page 11: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่ง (Statement)ค าสั่งใช้อธิบายการท างานของโปรแกรมในแต่ละขั้นตอน

เมท็อดถูกสร้างขึ้นจากค าสั่งตั้งแต่หนึ่งถึงหลายค าสั่ง

class Hello {

static void Main () {

System.Console.WriteLine("Hello World!");

System.Console.ReadLine();

}

}

Statement#1

Statement#2

Page 12: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่ง (Statement)namespace HelloW {

class HelloWClass {

static void Main () {

System.Console.WriteLine("Hello World!");

System.Console.ReadLine();

}

}

}

Page 13: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่ง (Statement)

method1

method2NamespaceClass

Statement#1

Statement#2

:

Page 14: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การตั้งชื่อ ทั้งเมท็อด คลาส เนมสเปส ต้องมีการตั้งชื่อก ากับ โดยในภาษา C# มีกฎ

การตั้งชื่อดังนี้◦ ขึ้นต้นด้วยอักขระภาษาอังกฤษ (A-Z, a-z) หรือตัวขีดเส้นใต้ (_)◦ ส่วนที่เหลือประกอบดว้ยอกัขระภาษาอังกฤษ ตัวเลข หรือตัวขีดเส้นใต้◦ ความยาวสูงสุด 63 ตัวอักษร◦ ต้องไม่ซ้ ากับค าสงวน (reserved words) เช่น class, namespace

ตัวอย่างชื่อที่ถูกกฎ◦ hEllO, E3_32ab, X_x_X022

ตัวอย่างชื่อที่ผิดกฎ◦ 32ABC, A.2, C#Program, while

Page 15: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสงวนค าเหล่านี้ห้ามน าไปใช้เป็นชื่อในภาษา C#

Page 16: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ตัวแปร (Variable)ตัวแปรใช้ส าหรับเก็บค่าของข้อมูล

การประกาศตัวแปร

การก าหนดค่าให้ตัวแปร

ตัวอย่าง

<type> <name>;

<name> = <expression>;

int width, height;

int area;

width = 10; height = 20;

area = width * height;

Page 17: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ชนิด ขนาด ความหมาย ช่วง

bool 1 byte ค่าความจริง (จริง-เท็จ) true / false char 2 byte อักขระโดด character code 0...65535sbyte 1 byte จ านวนเต็ม -128...127byte 1 byte จ านวนเต็มไม่ติดลบ 0...255int 4 bytes จ านวนเต็ม -2.1 x 109...2.1 x 109

uint 4 bytes จ านวนเต็มไม่ติดลบ 0...4.3 x 109

long 8 bytes จ านวนเต็ม -9.2 x 1018...9.2 x 1018

float 4 bytes จ านวนจริง ±1.5x10-45...±3.4x1038

double 8 bytes จ านวนจริงความละเอียดสองเท่า ±5.0x10-324...±1.7x10308

decimal 16 bytes จ านวนจริงความละเอียดสูง ±1.0x10--28...±7.9x1028

string N/A สายอักขระ N/A

Page 18: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การก าหนดค่าให้ตัวแปรเราสามารถก าหนดค่าเริ่มต้นให้กับตัวแปรได้พร้อมกับ

การประกาศตัวแปรนั้น ๆ ได้ทันที

ตัวอย่างint width = 10, height = 20;

int area;

area = width * height;

Page 19: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

นิพจน์ (Expressions)นิพจน์เป็นส่วนหนึ่งของค าสั่งที่ถูกประเมินเป็นค่าได้◦ อาจเป็นค่าโดดหรือประกอบขึ้นมาจากนิพจน์ที่เล็กกว่า

ตัวอย่างของนิพจน์ที่เป็นค่าโดด◦ ตัวเลข 3212, 3.1415

◦ อักขระ 'C'

◦ ค่าความจริง true or false

◦ ข้อความ "Hello, World"

◦ ตัวแปรหรือค่าคงที่ x, myName

Page 20: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

นิพจน์ทางคณิตศาสตร์นิพจน์ทางคณิตศาสตร์ (arithmetic expression) คือนิพจน์ที่ถูกตีความเป็นค่าจ านวนนิพจน์ทางคณิตศาสตร์สามารถน ามาประกอบเป็นนิพจน์ที่ซับซ้อนขึ้นได้โดยอาศัยตัวด าเนินการทางคณิตศาสตร์ (arithmetic operators)◦ +, -, *, /◦ % (ให้ค่าเศษจากการหาร)

ตัวอย่าง◦ 11+5 16◦ 11/2 5◦ 11.0/2 5.5◦ 11%2 1◦ 5.0%2.2 0.6

Page 21: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ล าดับการค านวณ (Precedence Rules)1. ( )

2. *, / , %

3. +, –

4. ซ้ายไปขวา

int Width,Height;

Width = 10*5+(16 * 12)/5;

Height = (16+5)+20%2;

Page 22: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การหารแบบจ านวนเต็มการหารนิพจน์ที่เป็นจ านวนเต็มสองจ านวนให้ผลลัพธ์เป็นจ านวนเต็มเสมอ◦ เศษจะถูกปัดทิ้ง

หากตัวตั้งและ/หรือตัวหารเป็นจ านวนทศนิยม (float หรือ double) การหารจะค านวณทศนิยมให้

int i1 = 10, i2 = 8;

double f1 = 10, f2 = 8;

double r1 = i1/i2; // r1 = 1

double r2 = f1/f2; // r2 = 1.25

double r3 = f1/i2; // r3 = 1.25

double r4 = i1/f2; // r4 = 1.25

double r1 = 10/8; // r1 = 1

double r2 = 10.0/8.0; // r2 = 1.25

double r3 = 10.0/8; // r3 = 1.25

double r4 = 10/8.0; // r4 = 1.25

Page 23: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่ง usingการใช้ค าสั่ง using <ชื่อเนมสเปส> ที่ต้นโปรแกรมเป็นการระบุว่าเราต้องการเรียกใช้งานคลาสในเนมสเปสนั้น ๆ

ตัวอย่าง: คลาส Console อยู่ในเนมสเปส System

using System;

class Hello {

static void Main () {

Console.WriteLine("Hello World!");

Console.ReadLine();

}

}

class Hello {

static void Main () {

System.Console.WriteLine("Hello World!");

System.Console.ReadLine();

}

}

Page 24: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่งส าหรับแสดงผลทางหน้าจอใช้ค าสั่ง Write หรือ WriteLine ซึ่งอยู่ในคลาส Console(ซึ่งอยู่ในเนมสเปส System อีกทีหนึ่ง)

การใช้งานพื้นฐาน:

การใช้งานชั้นสูง:

Console.WriteLine(”Size {0}x{1}”, width, height);

double salary=12000;

Console.WriteLine("My salary is {0:f2}.", salary);

Console.WriteLine("Hello");

Console.WriteLine(area);

Page 25: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ค าสั่งรับอินพุทใช้เมท็อด ReadLine ซึ่งอยู่ในคลาส Console◦ รับข้อมูลจากแป้นพิมพ์จนกว่าผู้ใช้จะกด Enter◦ ส่งค่าทั้งหมดให้โปรแกรมในรูปสตริง

ตัวอย่าง:string yourname;

yourname = System.Console.ReadLine();

Page 26: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ตัวอย่างโปรแกรม: ReadLineโปรแกรมด้านล่างจะให้ผู้ใช้ป้อนชื่อและกล่าวค าทักทายusing System;

class HelloYou

{

static void Main()

{

string name;

Console.Write("What is your name: ");

name = Console.ReadLine();

Console.WriteLine("Hello, {0}", name);

Console.ReadLine();

}

}

Page 27: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การเปลี่ยนสตริงให้เป็นตัวเลขเป็นที่ทราบว่าเมท็อด Console.ReadLine คืนค่าเป็นสตริง

ตัวเลขที่อยู่ในรูปสตริงไม่สามารถน าไปใช้ในการค านวณได้โดยตรง

ชนิดข้อมูลตัวเลขทุกชนิดมีเมท็อด Parse ซึ่งท าหน้าที่เปลี่ยนข้อมูลสตริงให้เป็นชนิดตัวเลขตามแบบข้อมูลนั้น ๆ

string s = "12";

int x = s+1; // Error!

string s = Console.ReadLine();

int x = int.Parse(s);

double y = double.Parse(s);

Page 28: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ตัวอย่าง: ค ำนวนพื้นที่สี่เหลี่ยมusing System;

class AreaCalculation

{

static void Main()

{

int width, height, area;

string input;

Console.Write("Enter width: ");

input = Console.ReadLine();

width = int.Parse(input);

Console.Write("Enter height: ");

input = Console.ReadLine();

height = int.Parse(input);

area = width * height;

Console.WriteLine("Area = {0}x{1} = {2}", width, height, area);

}

}

Obtaining "width"

Obtaining "height"

Page 29: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

แบบฝึกหัด: แก้สมกำรเขียนโปรแกรมเพื่ออ่านค่า x+y และ xy, จากนั้นให้ตอบว่าค่าของx และ y คือเท่าใด◦ เริ่มต้นจากการคิดขั้นตอนวิธี และเขียน pseudo-code◦ น า pseudo-code มาเขียนเป็นโปรแกรม

Page 30: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การเปลี่ยนชนิดข้อมูลตัวเลขการก าหนดค่าให้ตัวแปรที่เก็บข้อมูลได้ละเอียดมากกว่าท าได้ทันที◦ เนื่องจากข้อมูลไม่มีการสูญหาย

double float long int short sbyte

ulong uint ushort byte

char

ละเอยีดมาก ละเอยีดน้อย

Page 31: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การเปลี่ยนชนิดข้อมูลตัวเลขC# บังคับให้ระบุชนิดข้อมูลให้ชัดเจนส าหรับการก าหนดค่าให้ตัวแปรที่ละเอียดน้อยกว่า

int i = 50;

double d = i; // OK

double d = 5000.78;

long x = d; // ERROR!!!

long x = (long) d; // OK

ระบุชัดเจนว่าต้องการเปล่ียนค่า

double เป็น long

Page 32: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ตัวด าเนินการแบบ "modify-and-assign"เราสามารถผสมตัวด าเนินการทางคณิตศาสตร์บางตัวเข้ากับ "=" เพื่อใช้เป็นตัวด าเนินการแบบ modify-and-assign

ตัวอย่าง

รูปแบบค าสัง่ ความหมาย

var += expression เพ่ิมค่าใน var เป็นจ านวนเท่ากบั expression

var -= expression ลดค่าใน var เป็นจ านวนเท่ากบั expression

var *= expression คูณค่า var ด้วย expression เกบ็ผลลัพธใ์น var

var /= expression หารค่า var ด้วย expression เกบ็ผลลัพธใ์น var

sum += x; // ใหผ้ลเหมือนกบั sum = sum + x

prod *= 2.5; // ใหผ้ลเหมือนกบั prod = prod * 2.5

y -= 3+a; // ใหผ้ลเหมือนกบั y = y – (3+a)

Page 33: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

ตัวด าเนินการส าหรับเพิ่ม/ลดค่าตัวด าเนินการ ++ และ – ใช้ส าหรับเพิ่มและลดค่าให้ตัวแปรทีละ 1

ตัวอย่าง:

ค าสัง่ ผลลพัธ์

x++ เพ่ิมค่า x ขึ้น 1

x-- ลดค่า x ลง 1

int n = 0;

n++; // ใหผ้ลเหมือนกบั n = n+1, or n += 1

n++; // n มีค่าเท่ากบั 2

n--; // n มีค่าเท่ากบั 1

Page 34: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การเรียกใช้งานเมท็อดคลาสหลายคลาสมีเมท็อดชนิดสแตติก (static) ที่สามารถเรียกใช้ผ่านคลาสโดยตรงได้ทันที◦ เรียกเมท็อด methodName ผ่านคลาส className ที่อยู่ใน

เนมสเปส namespaceName

◦หากเนมสเปส namespaceName ถูกระบุผ่านค าสั่ง using ไว้ก่อนหน้านี้ การเรียกเมท็อดไม่จ าเป็นต้องระบุเนมสเปส

namespaceName.className.methodName(optional-arguments)

Page 35: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

การเรียกใช้งานเมท็อดเมท็อดที่ใช้งานบ่อย ๆ ได้แก่ System.Console.WriteLine()และ System.Console.ReadLine()

using namespaceName;

:

className.methodName(optional-arguments)

Page 36: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

คลาส Mathคลาส Math ในเนมสเปส System ได้เตรียมเมท็อดและค่าคงที่ไว้หลายตัวส าหรับการค านวณทางคณิตศาสตร์ที่ซับซ้อนขึ้น

ตัวอย่าง (บางส่วน):

Page 37: Introduction to Digital Logic - Weerayuth Khunrattanasiriweerayuth.in.th/docFiles/04-411-101/03-1-BasicComputer... · 2018-11-25 · มีโครงสร้างคล้ายกับภาษา

เมท็อด/ค่าคงท่ี ค่าที่คืนกลบัมา ตวัอย่างการใชง้าน ผลลพัธ์

PI ค่า Math.PI 3.1415927

Max(x,y) ค่าที่มากกว่าระหว่าง x และ y Math.Max(1,2) 2

Abs(x) ค่าสมับูรณข์อง x Math.Abs(-1.3) 1.3

Sqrt(x) รากที่สองของ x Math.Sqrt(4.0) 2.0

Round(x) ค่า x ที่ปัดเป็นจ านวนเตม็ Math.Round(0.8) 1

Pow(x,y) ค่า x ยกก าลัง y Math.Pow(3,2) 9.0

Log(x) ลอ็กฐานธรรมชาติของ x Math.Log(10) 2.302585

Ceiling(x) ค่า x ที่ปัดเศษขึ้น Math.Ceiling(4.1) 5

Cos(x) โคซายน์ของ x เรเดียน Math.Cos(Math.PI) -1