Linear search in array C programming
Logic for linear search is easy : you can see the c program in following steps:
//linear search:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],item,i,c=0;
for(i=0;i<4;i++)
{
printf("enter %d value:",i+1);
scanf("%d",&a[i]);
}
printf("enter to search:");
scanf("%d",&item);
for(i=0;i<4;i++)
{
if(item==a[i])
{
printf("%d found on %d\n",item,i+1);
c=c+1;
}
}
printf("count= %d",c);//counting the repeat
getch();
}
...............................
Result:
//linear search:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],item,i,c=0;
for(i=0;i<4;i++)
{
printf("enter %d value:",i+1);
scanf("%d",&a[i]);
}
printf("enter to search:");
scanf("%d",&item);
for(i=0;i<4;i++)
{
if(item==a[i])
{
printf("%d found on %d\n",item,i+1);
c=c+1;
}
}
printf("count= %d",c);//counting the repeat
getch();
}
...............................
Result:
Other C Programming:
C programming beginner from Hello World
Keywords in C programming
Palindrome and armstrong in function C programming
Nepali Flag in C programming
switch statement using character in C programming
Control Statement in C programming
Control Statements in C programming (if and else)
Program for Stack Using switch( PUSH POP DISPLAY and empty
Examples of while, Do while
Keywords in C programming
Palindrome and armstrong in function C programming
Nepali Flag in C programming
switch statement using character in C programming
Control Statement in C programming
Control Statements in C programming (if and else)
Program for Stack Using switch( PUSH POP DISPLAY and empty
Examples of while, Do while
Post a Comment