Gurux talabasi Baxtiyorov Zahiriddin 1-Amaliy ish Sonning tub yoki tub emasligini aniqlash


Download 150.48 Kb.
Sana21.06.2023
Hajmi150.48 Kb.
#1641626
Bog'liq
1 lab


951-20 gurux talabasi Baxtiyorov Zahiriddin 1-Amaliy ish
1.Sonning tub yoki tub emasligini aniqlash.
1) Dastur kodini tuzish.
#include
#include
using namespace std;

int main() {

int i, n;
bool tub = true;

cout << " natural sonni kiriting: ";


cin >> n;

if (n == 0 || n == 1) {


tub = false;
}

for (i = 2; i <=n/2; ++i) {


if (n % i == 0) {
tub = false;
break;
}
}

if (tub)
cout << n << " tub son";


else
cout << n << " tub son emas";

return 0;


}


2) ph da ferma testini hosil qilish
//php da ferma testini hosil qilish dasturini yaratish
//n soni tanlanadi shu sonni tubliks tekshiriladi n soni toq bo'lishi kerak;
$n=31;
//a soni ixtiyoriy tanlanadi
$a=2;
$k=pow($a,($n-1))%$n;
if ($k==1){
echo(" $n soni kata extimol bilan tub");
}
else{
echo(" $n soni tub emas");
}
?>
3) #include
using namespace std;

int gcd(int a, int b) {


if (b == 0) return a;
return gcd(b, a % b);
}

bool isMutualPrime(int a, int b) {


return gcd(a, b) == 1;
}

int main() {


int a, b;
cout << "ikki son kiriting: ";
cin >> a >> b;

if (isMutualPrime(a, b)) {


cout << a << " va " << b << " o`zaro tub." << endl;
} else {
cout << a << " va " << b << " o`zaro tub emas." << endl;
}

return 0;


}

Download 150.48 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling