Write a program Linear search in c program.
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int arry[5],i,n,search,flag=0;
clrscr();
printf("How many value enter:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d.Enter Value:",i);
scanf("%d",&arry[i]);
}
printf("Enter value of Search...");
scanf("%d",&search);
for(i=1;i<=n;i++)
{
if(arry[i]==search)
{
printf("\n%d is found at %d position in list.",search,i);
flag=1;
}
}
if(flag==0)
printf("Your Value does not in list.");
getch();
}
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int arry[5],i,n,search,flag=0;
clrscr();
printf("How many value enter:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d.Enter Value:",i);
scanf("%d",&arry[i]);
}
printf("Enter value of Search...");
scanf("%d",&search);
for(i=1;i<=n;i++)
{
if(arry[i]==search)
{
printf("\n%d is found at %d position in list.",search,i);
flag=1;
}
}
if(flag==0)
printf("Your Value does not in list.");
getch();
}
Comments
Post a Comment