Mã: Chọn tất cả
Uses Crt;
Function SNT(N : LongInt) : Boolean;
Var k : LongInt;
Begin
If N <= 1 Then Exit(False);
For k := 2 To N Div 2 Do
If N Mod k = 0 Then Exit(False);
Exit(True);
End;
Function BCNN(A, B : LongInt) : LongInt;
Var k : LongInt;
Begin
For k := Abs(A) To Abs(A*B) Do
If (k Mod A = 0) And (k Mod B = 0) Then Exit(k);
End;
Function UCLN(A, B : LongInt) : LongInt;
Var k : LongInt;
Begin
For k := Abs(A) DownTo 1 Do
If (A Mod k = 0) And (B Mod k = 0) Then Exit(k);
End;
Function LuyThua(A, B : LongInt) : LongInt;
Var k, KQ : LongInt;
Begin
If B = 0 Then Exit(1);
KQ := A;
For k := 2 To B Do KQ := KQ * A;
Exit(KQ);
End;
Function GiaiThua(N : LongInt) : LongInt;
Var k, KQ : LongInt;
Begin
If N < 0 Then Exit(0);
If N = 0 Then Exit(1);
KQ := 1;
For k := 2 To N Do KQ := KQ * k;
Exit(KQ);
End;
Procedure DoiSo(Var A, B : LongInt);
Var Tam : LongInt;
Begin
Tam := A;
A := B;
B := Tam;
End;
Procedure SapXepTang(Var Mang : Array Of LongInt; SL : LongInt);
Var k1, k2 : LongInt;
Begin
For k1 := 0 To SL - 2 Do
For k2 := k1 + 1 To SL - 1 Do
If Mang[k1] > Mang[k2] Then DoiSo(Mang[k1], Mang[k2]);
End;
Function LonNhat(Mang : Array Of LongInt; SL : LongInt) : LongInt;
Var k, Max : LongInt;
Begin
Max := Mang[0];
For k := 1 To SL - 1 Do
If Mang[k] > Max Then Max := Mang[k];
Exit(Max);
End;
Var M : Array[1..10000] Of LongInt;
i, N : LongInt;
X, Y : LongInt;
Begin
ClrScr;
X := -3; Y := 9;
WriteLn('X = ', X, ' | Y = ', Y);
WriteLn('Kiem tra so nguyen to X: ', SNT(X), ' | ', SNT(11));
WriteLn('Tim boi chung nho nhat cua X va Y: ', BCNN(X, Y), ' | ', BCNN(12, Y));
WriteLn('Tim uoc chung lon nhat cua X va Y: ', UCLN(X, Y), ' | ', UCLN(-32, 18));
WriteLn('Tinh luy thua X^Y: ', LuyThua(X, Y));
WriteLn('Tinh giai thua Y!: ', GiaiThua(Y), ' | ', GiaiThua(-2));
DoiSo(X, Y);
WriteLn('Doi so: X = ', X, ' | Y = ', Y);
{ DU LIEU KIEU MANG }
N := 3; M[1] := 10; M[2] := -5; M[3] := 8;
Write('Day so ban dau: ');
For i := 1 To N Do Write(M[i], ' ');
WriteLn;
SapXepTang(M, N);
Write('Day so sau khi sap xep: ');
For i := 1 To N Do Write(M[i], ' ');
WriteLn;
WriteLn('So lon nhat la: ', LonNhat(M, N));
ReadLn;
End.
► Tài liệu Google Drive: Nhấn để xem nội dung