#include<stdio.h> #include<conio.h> void main() { int a[30],x,n,i; /* a - for storing of data x - element to be searched n - no of elements in the array i - scanning of the array */ printf("Enter no of elements :"); scanf("%d",&n); /* Reading values into Array */ printf("Enter the values :"); for(i=0;i < n;i++) scanf("%d",&a[i]); /* read the element to be searched */ printf("Enter the elements to be searched"); scanf("%d",&x); /* search the element */ i=0; /* search starts from the zeroth location */ while(i < n && x!=a[i]) i++; /* search until the element is not found i.e. x!=a[i] search until the element could still be found i.e. i 〈 n */ if(i < n) /* Element is found */ printf("found at the location =%d",i+1); else printf("n not found"); getch(); }
About Me
- Amit Singh Thakur
- Raipur, Chhattisgarh, India
- Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.
Monday, September 2, 2013
C Program to Search an element in Array
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment