g) biron-bir tub sonning kubi. HA yoki YO‘Q javobini chop etish kerak.
43. To‘rtburchakni kvadratlarga ajratish. Tomonlari natural son bo‘lib, a va b ga teng bo‘lgan to‘rtburchak berilgan. Agar har doim to‘rtburchakdan yuzasi maksimal darajada bo‘lgan kvadrat kesib olinsa, uni tomonlari natural sonlar bilan ifodalangan nechta kvadratga ajratish mumkinligini aniqlovchi dastur tuzing.
44. Berilgan yuzali (yuza - natural son bilan ifodalangan kiritiladigan ma’lumot) tomonlari natural son bo‘lgan barcha to‘rtburchaklarni topish dasturini tuzing. Masalan, agar yuza 12 ga teng bo‘lsa, u holda biz uchta har xil to‘rtburchak hosil qilamiz:
Qirrasining o‘rnini almashtirganda biri ikkinchisidan hosil bo‘luvchi to‘rtburchaklarni bir xil deb hisoblaymiz.
{
unsigned int S;
cout << "S="; cin >> S;
for (int i = 1; i <= S; i++)
for (int j = 1; j <= i; j++)
if (i*j == S)
cout << i << "x" << j << endl;
return 0;
}
45. 2 ta sonning o‘zaro tub yoki tub emasligini , uchta sonning o‘zaro tub yoki tub emasligini tekshiruvchi dastur tuzing.
#include
#include using namespace std;
int TubA(int a, int b)
{
while (a != b)
{
if (a > b)
a = a - b;
else
b = b - a;
}
return a;
}
int main()
{
unsigned int a, b, c, k;
//-------------Ikki son uchun --------------//
cout << "a="; cin >> a;
cout << "b="; cin >> b;
cout << "c="; cin >> c;
k = TubA(a, b);
if (k == 1)
cout << "Bu ikki son o'zaro tub";
else
cout << "Bu ikkita son o'zaro tub emas!";
//-----------Uchta son uchun --------------//
k = TubA(TubA(a, b), c);
if (k)
cout << "Bu uchta son o'zaro tub";
else
cout << "Bu uchta son o'zaro tub emas!";
return 0;
}