Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- int seq_find(int a[], int n, int x){
- int i = 0;
- while((i < n) && (a[i] != x))
- i++;
- if (i == n) return -1; //Neu khong thay thi tra ve -1
- else return i;
- }
- int main(){
- int n, mang[50],i,x,tt;
- printf("\nNhap so phan tu cua mang: "); scanf("%d",&n);
- for(i = 0; i < n; i++){
- printf("a[%d]=",i+1);
- scanf("%d",&mang[i]);
- }
- printf("\nNhap vao gia tri can tim: ");
- scanf("%d",&x);
- tt = seq_find(mang,n,x);
- //Bien timthay>=0 danh dau ket qua da tim thay
- if (tt >= 0) printf("\nTim thay %d tai vi tri thu %d",x,tt);
- else printf("\nKhong co %d trong day vua nhap!",x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment