You are on page 1of 2

/* ROLL NO: 1 SEM-1 ICA DIV: A

NAME : VARUN AGGARWAL SUBJECT: FOP


PROGRAM DEFINITION:Write a program to search integer from the array..
*/

#include<stdio.h>
#include<conio.h>
#define size 10

int a[size];
int search(int);
void readarray();

int main()
{
int index,key;
clrscr();
readarray();
printf("\nEnter the value of key: ");
scanf("%d",&key);
index=search(key);
if(index==-1)
{
printf("\nSearch Unsuccessful...!!!");
}
else
{
printf("\nSearch Successful...!!!");
printf("\nIndex of %d is %d",key,index);
printf("\nAddress of %d th element is %u",(index+1),&a[index]);
}
getch();
return 0;
}

void readarray()
{
int i;
for(i=0;i<size;i++)
{
printf("\na[%d]: ",i);
scanf("%d",&a[i]);
}
}

int search(int key)


{
int i;
for(i=0;i<size;i++)
{
if(a[i]==key)
return i;
}
return -1;
}
/* OUTPUT:
a[0]: 1
a[1]: 2
a[2]: 3
a[3]: 4
a[4]: 5
a[5]: 6
a[6]: 7
a[7]: 8
a[8]: 9
a[9]: 10
Enter the value of key: 1
Search Successful...!!!
Index of 1 is 0
Address of 1 th element is 1380
*/

You might also like