Find a number in List C#

C Program To Search An Element In An Array | C Programs

in C Programs Comments Off on C Program To Search An Element In An Array | C Programs

C Program to search for an element in an array In this article, we will detail in on the various methods to search for an element in an array in C programming.

Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.

The means used in this specific piece are as follows:

  • Using Standard Method
  • Using Function
  • Using Recursion

As we all know, an array is a collection or sequential arrangement of elements in any given order. Arrays form the basics of the C programming language.

As you can see in the photo uploaded above, the elements are first entered in no particular order.

The elements entered here are 4, 6, 2, 1 and 3.

The target element is mentioned here as well. The target element here is 2.

Once the element is present in the array, it will say element found.

Thus, the several methods to find an element in an array are as follows:

Using Standard Method

  1. Read the array size and store that value into the variable n.

2]Read the entered elements and store those elements into an array a[] using scanfstatement and the for loop. scanf[%d,&a[i]] indicates scanf statement reads the entered element and assigned that element to a[i].

3]Read the key which we want to search in anarray.

4]Compare the key with each element of the array as a[i]==key and print element found,if the key matches with any element of the array otherwise print element not found.

C Program To Search An Element In An Array Using Standard Method
C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include
#include
int main[]
{
int a[10000],i,n,key;
printf["Enter size of thearray : "];
scanf["%d", &n];
printf["Enter elements in array : "];
for[i=0; i

Chủ Đề