Manfiy bo’lmagan butun sonlar massividan eng katta elementni toppish dasturini “Bo’lish va hukmronlik qilish” algoritmi yordamida aniqlash dasturi
Quydagi tasodifiy algoritm yordamida qidirish usuli qanday nomlanadi?
int a[11]={2,4,5,8,23,4,54,65,3,14,20};
do
{
i++;
b=rand()%11;
if(i>k) break;
cout<} while (c!=a[b]);
if(i>k) cout<<"\nIzlanayotgan son topilmadi ";
else{
cout<Select one:
Monte-Karlo
Quyidagi funksiya nima vazifani bajaradi?
int funk(int *a, int l, int r)
{
return l == r ? a[l] : funk(a, l, (l + r)/2) + funk(a, (l + r)/2 + 1, r);
}
..
{
funk(a, 0, N - 1);
}
Select one:
a massivning elementlari yig'indisini hisoblaydi
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
int x1, x2;
if (l == r)
return a[l]; else
{
x1 = funk(a, l, (l + r)/2); x2 = funk(a, (l + r)/2 + 1, r);
return x1 < x2 ? x1 : x2;
}
}
int main()
{
int a[]={2,7,7,5,6,5,4,3,6,7,8};
cout<}
2
... - Tasodifiy butun sonni hosil qilish funksiyasi (Funksiya())
Rand()
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
int x1, x2;
if (l == r)
return a[l]; else
{
x1 = funk(a, l, (l + r)/2); x2 = funk(a, (l + r)/2 + 1, r);
return x1 > x2 ? x1 : x2;
}
}
int main()
{
int a[]={2,7,7,5,6,5,4,3,6,7,8};
cout<}
7
Rand() funksiyasidan foydalanish uchun Ctime header fayli chaqiriladi
'False'
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
return l == r ? a[l] : funk(a, l, (l + r)/2) + funk(a, (l + r)/2 + 1, r);
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
cout<return 0;
}
36
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
return l == r ? a[l] : funk(a, l, (l + r)/2) + funk(a, (l + r)/2 + 1, r);
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
cout<return 0;
}
Do'stlaringiz bilan baham: |