C Program to Search Element in an Array
Write a C program to search an element in an array. This C program accepts an array and an element from user and checks whether given element is present in the array or not.
C Program to Search an Element in Array
/* Aim: Accept an array and a seperate number and check whether the number is in the array or not*/
#include<stdio.h>
void main()
{
int i,arr[5],num,LED=0;
printf("\n Enter any five numbers:- ");
for(i=0;i<=4;i++)
scanf("%d",&arr[i]);
printf("\n Enter any numbers:- ");
scanf("%d",&num);
for(i=0;i<=4;i++)
{
if(num==arr[i])
LED=1;
break;
}
if(LED==1)
printf("\n %d is in given array \n \n",num);
else
printf("\n %d is not in given array \n \n",num);
}
Output:
Enter any five numbers:- 1 2 3 4 5 Enter any numbers:- 9 9 is not in given array
Comments