顺序查找法

来源:互联网 发布:c语言获取开机时间 编辑:程序博客网 时间:2024/06/04 20:02
#include"stdio.h"int main(){    int a[5];    int i,flag=0,index,x;    for(i=0;i<5;i++)        scanf("%d",&a[i]);    printf("Give the x:");    scanf("%d",&x);    for(i=0;i<5;i++){        if(a[i]==x){       flag=1;            index=i;            break;        }    }    if(flag)        printf("x is founded and the index is %d!\n",index);    else        printf("x is not founded!\n");    return 0;}

0 0