answersLogoWhite

0

void main(){

int a[10],i,n,m,c=0;

clrscr();

printf("Enter the size of an array");

scanf("%d",&n);

printf("\nEnter the elements of the array");

for(i=0;i<=n-1;i++){

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

}

printf("\nThe elements of an array are");

for(i=0;i<=n-1;i++){

printf(" %d",a[i]);

}

printf("\nEnter the number to be search");

scanf("%d",&m);

for(i=0;i<=n-1;i++)

{

if(a[i]==m)

{

c=1;

break;

}

}

if(c==0)

printf("\nThe number is not in the list");

else

printf("\nThe number is found");

getch();

}

--------------------------------------------------------------------

Answer by Jatinder Pal Singh


#include
#include
void main()
{
clrscr();
int i,n,item,a[20];
printf("\nEnter no of elements=");
scanf("%d",&n);
printf("\nEnter %d elements=",n);
for(i=0;i{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be search=");
scanf("%d",&item);
for(i=0;i{
if(a[i]==item)
{
printf("\n\t%d is present at position %d",a[i],i+1);
break;
}
}
if(i==n)
printf("\nElement is not Present");
getch();
}
User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How can you convert a simple algorithm to recursive algorithm?

Linear search(a,item) n=length(a) for i=1 to n do if(a[i]==item) then return i end for return -1


Is breadth first search recursive in nature?

No, breadth-first search is not inherently recursive in nature. It typically uses a queue data structure to keep track of the nodes to visit next, rather than relying on recursive function calls.


Best first search program in c?

The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).


How do you run graphics program in C?

pro c language to implement linear search using pointers


Is BFS recursive?

No, Breadth-First Search (BFS) is not inherently recursive. It is typically implemented using a queue data structure rather than recursion.


Explain linear search with an example?

Sequential search of an object with in an array of objects is called as linear search.


How do you find a recursive rule?

You can search on ebay or more likey to find at Staples :)


What is linear searching?

The linear search algorithm is a special case of the brute force search.


What are advantage of linear searching?

There no advantages to linear search other than searching for the first (or last) nodes. Linear search takes linear time with an average O(n/2) for each search.


What is the running time of a linear search of an array?

Running time of a linear search is O(n)


Complexity of linear search?

the compexity of linear search in worst case is f(n) = n+1


What are the Advantages of binary search on linear search in c?

(i) Binary search can interact poorly with the memory hierarchy (i.e. caching), because of its random-access nature. For in-memory searching, if the interval to be searching is small, a linear search may have superior performance simply because it exhibits better locality of reference. (ii) Binary search algorithm employs recursive approach and this approach requires more stack space. (iii) Programming binary search algorithm is very difficult and error prone (Kruse, 1999).