answersLogoWhite

0


Best Answer

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

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int a[7], i=0;

clrscr();

printf("Enter the elements of the array :");

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

{

scanf("%d\n", &a[i]); /* taking input array from the user */

}

printf("\nThe elements of the array you have enetered are as follows :")

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

{

printf("%d", a[i]); /* printing the array elements or traversing the array */

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Yes.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for linear search using non recursive functiontion?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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


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


How do you find a recursive rule?

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


Explain linear search with an example?

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


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).


What is search algorithm?

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


What are the various applications of linear search in real time?

Linear search is necessary when we must search unordered sets. Linear search times across huge sets can be improved significantly by dividing the set amongst two or more threads that can execute on independent CPU cores.