EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

Write a program to find whether a given element is present in the given array

Source Code

#include<stdio.h>
#include<conio.h>
int main (int argc, char *argv[])
{
  clrscr();
  int ar[100];
  int r,t,i,f;
  for(i=0;i<100;i++)
  {
10      ar[i]=0;
11    }
12    printf("\n Enter the range:(less than 100) ");
13    scanf("%d",&r);
14    printf("\n Enter the elements of the array:");
15    for(i=0;i<r;i++)
16    {
17         printf("\n Enter element number: %d ",(i+1));
18         scanf("%d",&ar[i]);
19    }
20    printf("\n Enter the element to be searched:");
21    scanf("%d",&t);
22    for(i=0;i<r;i++)
23    {
24          if(ar[i]==t)
25          {
26        f=1;
27        break;
28          }
29    }
30    if(f==1)
31    {
32      printf("\n The Element %d is present in the array",t);
33    }
34    else
35    {
36      printf("\n The Element %d is not present in the array",t);
37    }
38    getch();
39  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code