Data Structure and Algorithm 1CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT Tìm giai thừa bằng đệ qui Dr.. Data Structure and Algorithm 2Wayne, edit by Dao Nam Anh.. Major Reference: • Robert Sedgewick
Trang 1Data Structure and Algorithm 1
CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT
Tìm giai thừa bằng đệ qui
Dr Dao Nam Anh
Trang 2Data Structure and Algorithm 2
Wayne, edit by Dao Nam Anh
Major Reference:
• Robert Sedgewick, and Kevin Wayne, “Algorithms”
Princeton University, 2011, Addison Wesley
• Algorithm in C (Parts 1-5 Bundle)- Third Edition by
Robert Sedgewick, Addison-Wesley
• Cấu trúc dữ liệu và giải thuật, Đinh Mạnh Tường.
Sư Phạm, 2002
Trang 3Data Structure and Algorithm 3
pubic class Factorial {
public static int fact ( int n ) {
if ( n == 0 ) return 1 ;
else return n * fact ( n - 1 );
}
public static void main ( String [] args ) {
System out println ( fact ( 3 ));
}
}
Trang 4Data Structure and Algorithm 4
}
Trang 5Data Structure and Algorithm 5
}
Trang 6Data Structure and Algorithm 6
}
Trang 7Data Structure and Algorithm 7
Trang 8Data Structure and Algorithm 8
Trang 9Data Structure and Algorithm 9
Trang 10Data Structure and Algorithm 10
Trang 11Data Structure and Algorithm 11
Trang 12Data Structure and Algorithm 12
Trang 13Data Structure and Algorithm 13
Trang 14Data Structure and Algorithm 14
Trang 15Data Structure and Algorithm 15
Trang 16Data Structure and Algorithm 16
Trang 17Data Structure and Algorithm 17
1
Trang 18Data Structure and Algorithm 18
Trang 19Data Structure and Algorithm 19
2
Trang 20Data Structure and Algorithm 20
Trang 21Data Structure and Algorithm 21
% java Factorial
6
public class Factorial {
public static int fact ( int n ) {
if ( n == 0 ) return 1 ;
else return n * fact ( n - 1 );
}
public static void main ( String [] args ) {
System out println ( fact ( 3 ));
}
}
6