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
Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th

Define a structure in C++: Write a program a structure in c++ program. void main() {                 struct player                 {                 char name[2

Explain the Formatted Input Output with Strings? These are the third set of the scanf and printf families. They are called sscanf and sprintf. sprintf Puts formatted dat

how to create the programs in c++ knowledge

for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the


The program will consist of two text fields, two buttons, and a counter label.  One text field will be input, where the user types the plain text.  The second text field will be ou

Develop a program to meet the following requirements: 1. Must use at least one function in addition to main (you can use more) 2. Must use selection 3. Must use deference/indire

Destructor: The purpose of destructor is to free the memory when the compiler memory is reduced or not enough to execute certain program. Sometimes there may several objects op

how are metric numer change the number of metric