linear search
hello, program with full explanation
#include<stdio.h>
#include<conio.h>//header file
int main(){
int i=0,item;// i will check from 0 to laast element
int a[5]={1,2,3,4,5}; // array element
printf("enter digit you want to search");
scanf("%d",&item);
while(a[i]<5){ //if array of i is less than 5
if(a[i]==item){ // here cheeck is equal to item or
// not
printf("item location %d",i+1);// if match it will
//print the location
break;
}i++; //affter chekinh 0 it will go to next as 1 to 5
if(i>=5){
printf("not found");//if not = to array it will prinnt
}
}
return 0;
Comments
Post a Comment
welcome user , hope you good