Dastur kodi #include using namespace std; int search
tarix 11.11.2022 ölçüsü 55,42 Kb. #68487
2-amalliy ish mta
AMALIYOTY ISHI-2
Mavzu: QIDIRISH VA SARALASH ALGORITMLARI
VARIANT-27
Chiziqli qidirish algoritmidan foydalanib , [-10;1000] gacha bo’lgan saralangan toq sonlar ichidan siz qidirayotkan son bor yoki yo’qligini tekshiruvchi dastur tuzing.
DASTUR KODI
#include
using namespace std ;
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)
? cout << "Element is not present in array"
: cout << "Element is present at index " << result<
cout<
return 0;
}
NATIJA
Dostları ilə paylaş: