C program to search an element in the array using a user – defined function.

#include <stdio.h>

int arraySearch(int arr[],int size,int n)
{
  // arr >> array
  // size >> array size
  // n >> number to search
  
  int i;
  
  for(i=0;i<size;i++)
  {
    if(n==arr[i])
    {
	  return 1; // if number is present
	}
  }
  
  return 0;
}


int main()
{
	int arr[5]={10,15,18,21,33};
	int n;
	
	printf("Enter a number you want to search : ");
	scanf("%d",&n);
	

	if(arraySearch(arr,5,n))
	  printf("Number is present in the Array \n");
    else
      printf("Number is NOT present in the Array \n");
	
	return 0;
}
OUTPUT:
RUN 1)
Enter a number you want to search : 18
Number is present in the Array

RUN 2)
Enter a number you want to search : 25
Number is NOT present in the Array

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.