C program to search an element in an array



#include <stdio.h>
#include <conio.h>
void main()
{
 int array[10];
 int i, N, keynum, found=0;
 clrscr();
 printf("Enter the value of N\n");
 scanf("%d",&N);
 printf("Enter the elements one by one\n");
 for(i=0; i<N ; i++)
 {
  scanf("%d",&array[i]);
 }
 printf("Input array is\n");
 for(i=0; i<N ; i++)
 {
  printf("%d\n",array[i]);
 }
 printf("Enter the element to be searched\n");
 scanf("%d", &keynum);
 for ( i=0; i < N ; i++)
 {
  if( keynum == array[i] )
  {
   found = 1;
   break;
  }
 }
 if ( found == 1)
  printf("SUCCESSFUL SEARCH\n");
 else
  printf("Search is FAILED\n");


Output:

searching element in array , C prograaming C programs

Post a Comment

 
Top