Home / Programs / C Program to Search an element in Array
🚀 Programming Example

C Program to Search an element in Array

👁 1,785 Views
💻 Practical Program
📘 Step Learning
C Program to Search an element in Array

💻 Program Code

 /*
C Program to Search an element in Array
 Author: atnyla Developer
 */

  
#include<stdio.h>
 
int main() {
   int a[30], ele, num, i;
 
   printf("\nEnter no of elements :");
   scanf("%d", &num);
 
   printf("\nEnter the values :");
   for (i = 0; i < num; i++) {
      scanf("%d", &a[i]);
   }
 
   //Read the element to be searched
   printf("\nEnter the elements to be searched :");
   scanf("%d", &ele);
 
   //Search starts from the zeroth location
   i = 0;
   while (i < num && ele != a[i]) {
      i++;
   }
 
   //If i &lt; num then Match found
   if (i < num) {
      printf("Number found at the location = %d", i + 1);
   } else {
      printf("Number not found");
   }
 
   return (0);
}
 
                        

🖥 Program Output


Enter no of elements :5

Enter the values :2 3 5 4 6

Enter the elements to be searched :5
Number found at the location = 3 
                            

📘 Explanation

C Program to Search an element in Array
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.