Linear search in array - c program, C/C++ Programming

Linear search in array - C program:

Write a program in c to define a linear search in array.

void main()

                {

                clrscr();

                int a[100] , ch , n;

                cout<<"enter the nit for the array : ";

                cin>>n;

                for (int i=0;i

                                {

                                cout<<"enter element "<

                                cin>>a[i];

                                }

                  Cout<< "Linear search:"

                        lsearch (a,n);

                getch();

                } //main

 

 

 

void lsearch (int a[100] , int n)

                {

                int i,ele,found=0,pos=-1;

                cout<<"enter the element to be searched : ";

                cin>>ele;

                for (i=0;i

                                {

                                if (a[i] == ele)

                                                {

                                                found = 1 ;

                                                pos = i;

                                                }

                                }

                if (found ==-1)

                                {

                                cout<<"element not found";

                                }

                else

                                {

                                cout<<"element found at "<

                                }

                }

 

Posted Date: 10/19/2012 3:11:36 AM | Location : United States







Related Discussions:- Linear search in array - c program, Assignment Help, Ask Question on Linear search in array - c program, Get Answer, Expert's Help, Linear search in array - c program Discussions

Write discussion on Linear search in array - c program
Your posts are moderated
Related Questions
smugglers transfer the messages from one to another by using the mobile

Described the difference among "new" and "operator new" ? A:"operator new" works such as malloc.

Write a C program to compute the factorial of  5 i.e. 1x2x3x4x5 etc Write a C program to calculate the output Y for a given value of X for the following formula.       Y=X 2

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Need an indicator Project Description: Need an indicator which indicates target and trailing sl after entering trades. Skills required are C Programming, C++ Programming,

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Description - The TR-069 CPE WAN Management Protocol (CWMP) is a protocol that was created by the Broadband Forum (formally the DSL Forum) which sets out a common method for CPE de

can you tell me what is c#