// Tim kiem tuyen tinh (LinearSearch) #include<stdio.h> #include<conio.h> int LinearSearch1(int Day[],int n,int x) { int vitri=0; while(vitri<n&&Day[vitri]!=x) vitri++; if(vitri==n) return -1; else return 1; } int LinearSearch2(int Day[],int n,int x) { int vitri=0; while(vitri<n&&Day[vitri]!=x) vitri++; if(vitri==n) return -1; else return vitri; } int Mang[10]={1,2,3,4,5,6,7,8,9,10}; int X; void main() { clrscr(); printf("Nhap x can tim: "); scanf("%d",&X); printf("Ket qua tim kiem la: %d",LinearSearch1(Mang,10,X)); printf("\n%d o vitri %d ",X,LinearSearch2(Mang,10,X)); getch(); }
nosomovo