Saturday 11 January 2014

A C++ program to perform linear search.

#include<iostream.h>
#include<conio.h>
Void main()
{
            Int a[100],n,ser;
Clrscr();
            Cout<<’\n Enter The Size of the value:”;
            Cin>>n;
Int i;
            For(i=0;i<n;i++)
            {
                        Cout<<”\n Enter A[<<i<<”] : “;
                        Cin>>a[i];
            }
            Cout<<’\n Enter The value to be search in the given array :”;
            Cin>>ser;
            Int b=0;
For(i=0;i<n;i++)
            {
                        If(a[i]==ser)
                        {
                                    b=1;
                        }
            }
            If(b==0)
            {
                        Cout<<”\n value not found”;
            }else{
                        Cout<<”\n Value found “;
            }
            Getch();

}

No comments:

Post a Comment