Friday, August 2, 2013

Program to search element in an array - Linear search

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int n,p=-1;
char a[100],s;
cout<<"Enter the line of text : ";
gets(a);
cout<<"Enter the character to be searched : ";
cin>>s;
for(int i=0;a[i]!='\0';++i)
if(a[i]==s)
p=i;
if(p>=0)
cout<<"Character found in "<<p<<"th position";
else
cout<<"Character not found ";
getch();
}

No comments:

Post a Comment