Here is the code..
//AIM: TO PERFORM LINER SEARCH
#include<stdio.h>
#define m 10
void main()
{
int a[m],i,j,n,p;
printf("enter the no of elements (less than 10)\n");
scanf("%d",&p);
printf("Enter %d elements of an array\n",p);
for(i=0;i<p;i++)
scanf("%d",&a[i]);
printf("entered array is:\n");
for(i=0;i<p;i++)
printf("%d\t",a[i]);
printf("\nenter the element you want to search\n");
scanf("%d",&n);
for(i=0;i<p;i++)
{
if(n==a[i])
{
j=100;
break;
}
}
if(j==100)
printf("ELEMENT IS PRESENT AT %d POSITION\n",(i+1));
else
printf("ELEMENT IS NOT PRESENT\n");
}
For Turbo C users.
//AIM: TO PERFORM LINER SEARCH
#include<stdio.h>
#include<conio.h>
#define m 10
void main()
{
int a[m],i,j,n,p;
clrscr();
printf("enter the no of elements (less than 10)\n");
scanf("%d",&p);
printf("Enter %d elements of an array\n",p);
for(i=0;i<p;i++)
scanf("%d",&a[i]);
printf("entered array is:\n");
for(i=0;i<p;i++)
printf("%d\t",a[i]);
printf("\nenter the element you want to search\n");
scanf("%d",&n);
for(i=0;i<p;i++)
{
if(n==a[i])
{
j=100;
break;
}
}
if(j==100)
printf("ELEMENT IS PRESENT AT %d POSITION\n",(i+1));
else
printf("ELEMENT IS NOT PRESENT\n");
getch();
}
No comments:
Post a Comment