C Program to Find a Number in an Array

Below is a simple C program that searches for a given number in an array. The program prompts the user to enter the size of the array, the elements of the array, and the number to be searched. It then prints whether the number is found in the array or not.

Program :

#include <stdio.h>
#include <conio.h>
 
 
int main()
{
    int a[10000],i,n,key;
   
    printf(“Enter size of the  array : “);
    scanf(“%d”, &n);
    printf(“Enter elements in array : “);
    for(i=0; i<n; i++)
    {
        scanf(“%d”,&a[i]);
    }
     printf(“Enter the key : “);
    scanf(“%d”, &key);
     
    for(i=0; i<n; i++)
    {
        if(a[i]==key)
        {
printf(“element found “);
            return 0;  
        }
 
    }
    
printf(“element  not  found”);
}

Output :

Leave a Comment

Your email address will not be published.

Shopping Basket
Verified by MonsterInsights