Guruh talabasi Omonbayev Jaloliddin Mavzu


Download 27.57 Kb.
Sana04.01.2023
Hajmi27.57 Kb.
#1078393
Bog'liq
14. Qidiruv algoritmlarining qiyosiy tahlili


911-21 guruh talabasi Omonbayev Jaloliddin

Mavzu : Qidiruv algoritmlarining qiyosiy tahlili


  1. Massivni toq va juft elementlari yig’indisi .

#include

using namespace std;
void EvenOddSum(int arr[], int n)
{
int even = 0;
int odd = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
even += arr[i];
else
odd += arr[i];
}

cout << "Toq elementlari yig'indisi " << even;


cout << "\nJuft elementlari yig'indisi " << odd;
}

int main()


{
int arr[] = { 1, 2, 3, 4, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);

EvenOddSum(arr, n);

return 0;
}




2.

#include

int search(int arr[], int N, int x)
{
int i;
for (i = 0; i < N; i++)
if (arr[i] == x)
return i;
return -1;
}
int main(void)
{
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int N = sizeof(arr) / sizeof(arr[0]);

int result = search(arr, N, x);


(result == -1)
? printf("Element massivda mavjud emas")
: printf("Element %d indeksida mavjud", result);
return 0;
}


Download 27.57 Kb.

Do'stlaringiz bilan baham:




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