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
Define Types of storage classes in C language? There are four storage classes in C language: 1. Automatic storage class. 2. External storage class. 3. Register storage cla

i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

Develop Custom Mql4 Code/Fxdreema block Project Description: I need the subsequent code written in mql4 and integrated as custom block(s) in fxdreema: for each trade: C

write a c program to solve exanple of lamis therom

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules:

What are header files? What are their uses? - Header files are also known as library files. - They carry two significant things: definitions and prototypes of functions bein

Differentiate between functions getch () and getche (). - Both functions accept a character input value from user. - When getch () is used, key that was pressed won't appear

Write a function that takes in a radius and evenly covers the screen with circles of that radius. Don't attempt to draw any circles that are completely off the screen.

Depreciation to a salvage value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight line method of depreciati