(Xn) X ning n chi darajaga ko’tarish funksiyasi double step (double x, int n) { if(!n) return 1; else return x*step (x, n-1); } - Ikkita a va b sonlari berilgan ularning EKUBini topuvchi dastur tuzing.
- EKUB inglizchada Greatest common divisor qisqacha gcd(a, b).
- Masalan
gcd(25, 20) = 5; gcd(60, 70)=10. Eramizdan oldingi 325 yilda tug’ilgan. Grek matematigi, geometriyaning otasi. Evklid algoritmi eng qadmgi algoritmlardan biri. Eramizdan oldingi 325 yilda tug’ilgan. Grek matematigi, geometriyaning otasi. Evklid algoritmi eng qadmgi algoritmlardan biri.
Evklid
- Evklid algoritmi bo’yicha:
gcd(a, b) =
- Masalan:
gcd(124, 36)
- a=124,b=36,b≠0. gcd(124,36)=gcd(36,124%36)=gcd(36, 16)
- a=36, b=16, b≠0. gcd(36, 16)=gcd(16, 36%16)=gcd(16, 4)
- a=16, b=4, b≠0. gcd(16, 4)=gcd(4, 16%4)=gcd(4, 0)
- a=4, b=0. gcd(4, 0) = 4;
- Demak gcd(124, 36)=4.
int gcd(int a, int b) { if (b==0) return gcd(b, a % b); } E’tiboringiz uchun rahmat
Do'stlaringiz bilan baham: |