Problem: Sequential Search Algorithm
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int *a,size,i,t,flag=0;
clrscr();
printf("ENTER THE SIZE OF ARRAY:");
scanf("%d",&size);
a=(int *)malloc(size*sizeof(int));
printf("\nENTER %d VALUES IN ARRAY: ",size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("\nENTER THE VALUE YOU WANT TO FIND IN ARRAY:");
scanf("%d",&t);
for(i=0;i<size;i++)
{
if(a[i]==t)
{
printf("\n%d is located at %d index and %d position",t,i,i+1);
flag=1;
}
}
if(flag==0)
{
printf("%d is not located in this array",t);
}
getch();
}
Comments