//WAP to implement Linear Search.
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int array[10], i, N, keynum, found=0; // required variables
clrscr(); // clearing the console screen
printf("Enter the size of array\n");
scanf("%d",&N); //inputting array size
void main()
{
int array[10], i, N, keynum, found=0; // required variables
clrscr(); // clearing the console screen
printf("Enter the size of array\n");
scanf("%d",&N); //inputting array size
printf("Enter the elements one by one\n");
for(i=0; i<N ; i++)
{
scanf("%d",&array[i]); // inputting array elements
}
for(i=0; i<N ; i++)
{
scanf("%d",&array[i]); // inputting array elements
}
printf("Enter the element to be searched\n");
scanf("%d", &keynum); // element to be searched
//Searching the element inside the array
for ( i=0; i < N ; i++)
{
if( keynum == array[i] )
{
found = 1; // in case the element is found
break;
}
}
scanf("%d", &keynum); // element to be searched
//Searching the element inside the array
for ( i=0; i < N ; i++)
{
if( keynum == array[i] )
{
found = 1; // in case the element is found
break;
}
}
if ( found == 1)
printf("SUCCESSFUL SEARCH\n");
else
printf("Search is FAILED\n");
getch(); // for holding the console screen
}
printf("SUCCESSFUL SEARCH\n");
else
printf("Search is FAILED\n");
getch(); // for holding the console screen
}
No comments:
Post a Comment