//WAP to implement Array Search
#include <stdio.h>#include <conio.h>
void main()
{
int array[10], i, N, keynum, found=0;
clrscr();
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
}
printf("Enter the element to be searched\n");
scanf("%d", &keynum); // element to be searched 'keynum'
for ( i=0; i < N ; i++)
{
if( keynum == array[i] ) // logic for searching
{
found = 1;
break;
}
}
scanf("%d", &keynum); // element to be searched 'keynum'
for ( i=0; i < N ; i++)
{
if( keynum == array[i] ) // logic for searching
{
found = 1;
break;
}
}
if ( found == 1)
printf("SUCCESSFUL SEARCH\n"); // search successful
else
printf("Search is FAILED\n"); // otherwise
getch(); // for holding the console screen
}
printf("SUCCESSFUL SEARCH\n"); // search successful
else
printf("Search is FAILED\n"); // otherwise
getch(); // for holding the console screen
}
No comments:
Post a Comment