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
Why should I employ new instead of truthful old malloc()? A: Constructors/destructors, type safety, overridability. Constructors/destructors: unlike malloc(sizeof(Fred)), new

Problem 1. Explain Break and continue statements in C++. Explanation of Break statement Explanation of Continue statement 2. Explain concepts of constructors and

A: A smart pointer is a C++ class which mimics a regular pointer in syntax and some semantics, however it does more. Since smart pointers to distinct types of objects tend to have

Write a simple program in C++ to investigate the safety of its enumeration types. Include at least 10 different operations on enumeration types that are incorrect/unsafe things to

Project Description: I posted listings on a site that is like eBay but for video games. I post the similar listing many times daily, but need something that will let me post

i need a program that generates this output: The highest card wins! Suit Order is: clubs, diamonds, hearts and spades The computers card is the 5 of Spades. The player’s card is t

Q: But MFC appear to encourage the employ of catch-by-pointer; should I do the similar? A: Depends. If you're utilizing MFC and catching one of their exceptions, by all means, d

A: In C++ the access privileges are public, private and protected. The default access level assigned to members of a class is private. Private members of any class are accessible o

Your program will read two kinds of data from two files: names and predicates. It will read a formal expression from standard input and check whether that expression is syntactical