ads

Sunday, 28 August 2016

c program to find/search a element in an array

#include<stdio.h>
#include<conio.h>
void main()
{
  int a[50],i,n,flag;
  printf("enter numbers of element in an array:");
  scanf("%d",&n);
  printf("enter the numbers:");
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  printf("enter the element you want to search:");
  scanf("%d",&s);
  for(i=0;i<n;i++)
  {
     if(s==a[i])
     flag=1;
     break;
  }
  if(flag==1)
  printf("number is present");
  else
  printf("number is absent");
  getch();

No comments:

Post a Comment