C Program to Search element in Array

Write a C Program to Search element in Array:

Required Knowledge:

C basics, Arrays

Program:

 1 #include <stdio.h>
 2  void main()
 3  {
 4      int arr[5],i,search;
 5  
 6      printf(" Enter element: ");
 7  
 8      for(i=0; i<5; ++i)
 9      {
10          scanf("%d",&arr[i]);
11      }
12      printf("\n Enter the number you want to search:");
13  
14      scanf("%d",&search);
15  
16      for(i=0; i<5; i++)
17      {
18          if(search==arr[i])
19          {
20              printf("\n\nThe number %d is at location:%d",search,i+1);
21              break;
22          }
23      }
24      if(search!=arr[i])
25          printf("\nNot found");
26  
27  
28  }
29  

Output:



Comments

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers