C++Program to find enter value using Linear search
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[10],i,no,found=0;
clrscr();
cout<<"Enter 10 values \n";
for(i=0;i<10;i++)
cin>>arr[i];
cout<<"Enter values to find: ";
cin>>no;
i=0;
while(!found && i<10)
{
if(arr[i]==no)
found=1;
else
i++;
}
if(found)
cout<<"Values found on "<<i<<" index";
else
cout<<"Value not found";
getch();
}
#include<conio.h>
void main()
{
int arr[10],i,no,found=0;
clrscr();
cout<<"Enter 10 values \n";
for(i=0;i<10;i++)
cin>>arr[i];
cout<<"Enter values to find: ";
cin>>no;
i=0;
while(!found && i<10)
{
if(arr[i]==no)
found=1;
else
i++;
}
if(found)
cout<<"Values found on "<<i<<" index";
else
cout<<"Value not found";
getch();
}
No comments:
Post a Comment