C Program–To search a number in a given array

//This program is to search a given number in an array
#include <stdio.h>
#include <conio.h>

int main()
{
    int a[10],i,num;
    printf("enter the array elements");
    for(i=0;i<10;i++) //get all the numbers
    scanf("%d",&a[i]);
    printf("Enter the number to search");
    scanf("%d",&num);
    for(i=0;i<10;i++)
    {
                     if(a[i]==num) //given num is matched in the array
                     {
                     printf("The number is found in the %d position",i+1);
                     getch();
                     exit(0); //to go the end of the program
                     }
    }
printf("The number is not found"); //if num not found, this will be displayed
getch();
return 0;
}

Comments

Popular Posts