0
#include<iostream.h>
int liner(int [], int ,int );
void main ()
{
	int a[1000];
	int arraysize,element;
int searchkey;
cout<<"Enter how many elements in your array";
cin>>arraysize;
cout<<"enter the elements of the array ";
for(int i=0;i<arraysize;i++)
cin>>a[i];
cout<<"Enter the searchkey";
cin>>searchkey;
element=liner (a,searchkey,arraysize);
if (element!=-1)
cout<<"::::Found value in index \n"<<element<<"\n";
else 
cout<<"::::value not found :::::\n";
}
int liner(int array[], int key ,int size){
	int index=-1;
	for(int n=0;n<size;n++)
		if (array[n]==key)
			index =n;
		return index;
}

is this code true .
i search about the value .and return its index
but how i can input index and return its value

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by programing
0

I'm not sure what you mean by extract a value. Do you mean get the value?

This gets the value of the nth element of array.

int value = array[n];

A note on style, search functions usually return the address of first element match. Your function returns the value of the last one. Why does this matter? Well if you return the address of the first match, it gives a point to search for more matches.

Edited by gerard4143: n/a

0

yes i mean get value ..
i should to search about the value if its there or not .
also to get avalue from adress i should to chick if the adress is out of memmory

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.