1. Trang chủ
  2. » Giáo án - Bài giảng

Bài giảng cấu trúc dữ liệu và giải thuật thực hiện thuật toán euclid bằng đệ qui TS đào nam anh

21 189 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 752,08 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Data Structure and Algorithm 1CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT Thực hiệu thuật toán Euclid bằng đệ qui Dr.. Data Structure and Algorithm 2and Kevin Wayne.. Major Reference: Princeton Unive

Trang 1

Data Structure and Algorithm 1

CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT

Thực hiệu thuật toán Euclid bằng đệ qui

Dr Dao Nam Anh

Trang 2

Data Structure and Algorithm 2

and Kevin Wayne

Major Reference:

Princeton University, 2011, Addison Wesley

• Algorithm in C (Parts 1-5 Bundle)- Third Edition by

Robert Sedgewick, Addison-Wesley

Trang 3

Data Structure and Algorithm 3

Tìm ước số chung lớn nhất của hai số nguyên

public class Euclid {

public static int gcd (int p , int q ) {

if ( q == 0 ) return p ; else return gcd ( q , p % q );

}

public static void main ( String [] args ) {

int p = Integer parseInt ( args [ 0 ]);

int q = Integer parseInt ( args [ 1 ]);

System out println ( gcd ( p , q ));

} }

Trang 4

Data Structure and Algorithm 4

}

Trang 5

Data Structure and Algorithm 5

if (q == 0 ) return p;

else return gcd (q, p % q);

}

Trang 6

Data Structure and Algorithm 6

}

Trang 7

Data Structure and Algorithm 7

Trang 8

Data Structure and Algorithm 8

Trang 9

Data Structure and Algorithm 9

Trang 10

Data Structure and Algorithm 10

p = 192, q = 24

p = 216, q = 192

environment

Trang 11

Data Structure and Algorithm 11

p = 192, q = 24

p = 216, q = 192

environment

Trang 12

Data Structure and Algorithm 12

p = 192, q = 24

p = 216, q = 192

environment

Trang 13

Data Structure and Algorithm 13

static int gcd (int p, int q) {

Trang 14

Data Structure and Algorithm 14

static int gcd (int p, int q) {

Trang 15

Data Structure and Algorithm 15

static int gcd (int p, int q) {

Trang 16

Data Structure and Algorithm 16

24

p = 192, q = 24

p = 216, q = 192

environment

Trang 17

Data Structure and Algorithm 17

Trang 18

Data Structure and Algorithm 18

Trang 19

Data Structure and Algorithm 19

Trang 20

Data Structure and Algorithm 20

Trang 21

Data Structure and Algorithm 21

if (q == 0 ) return p;

else return gcd (q, p % q);

}

24

public class Euclid {

public static int gcd (int p , int q ) {

if ( q == 0 ) return p ;

else return gcd ( q , p % q );

}

public static void main ( String [] args ) {

int p = Integer parseInt ( args [ 0 ]);

int q = Integer parseInt ( args [ 1 ]);

System out println ( gcd ( p , q ));

Ngày đăng: 06/11/2017, 12:35

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN