0% found this document useful (0 votes)
14 views4 pages

Lab Manual Ds

Uploaded by

aditi gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Lab Manual Ds

Uploaded by

aditi gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program :1 To search an element in the array using Linear Search.

#include<stdio.h>

#include<conio.h>

void main()

int a[10],i,item,flag=0;

//clrscr();

printf("Enter the data in the array");

for(i=0; i<10; i++)

scanf("%d",&a[i]);

printf("Enter the element to be searched");

scanf("%d",&item);

for(i=0; i<10; i++)

if(item==a[i])

flag=1;

break;

if(flag==0)

printf("Element Not Found");


else

printf("Element Found at Position =%d",i);

getch();

Aim: - To search an element in the 2-dimensional array using Linear Search.

#include<stdio.h>
#include<conio.h>
void main()
{

inta[3][3],i,j,item,flag=0;
clrscr();
printf("Enter the data in the array");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{

scanf("%d",&a[i][j]);
}

printf("Enter the element to be searched");


scanf("%d",&item);
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{

if(item==a[i][j])
{

flag=1;
printf("Element found at position=%d,%d",i,j);
}

if(flag==0)
printf("Element Not Found");

getch();
}
}

You might also like