Discussion Forums

New User? Please read instructions!

C program for linear search  

  RSS

thiyagarajan.s
Active Member
Joined: 1 month  ago
Posts: 14
27/01/2017 10:11 am  

C program for linear search


ReplyQuote
prakash
Eminent Member
Joined: 1 month  ago
Posts: 20
16/02/2017 2:55 pm  

C program for linear search:

 

#include <stdio.h>

int main()

{

     int a[250], search, c, n;

     printf("Please enter number of elements\n");

     scanf("%d",&n);

 

     printf("Enter the elements one by one\n", n);

     for (c = 0; c < n; c++)

     {

          scanf("%d", &a[c]);

     }

 

     printf("Enter the element to be searched\n");

     scanf("%d", &search);

 

     for (c = 0; c < n; c++)

     {

           if (a[c] == search)   

           {

                printf("%d is found at the location %d.\n", search, c+1);

                break;

           }

     }

     if (c == n)

          printf("Element %d is not found in the list.\n", search);

 

     return 0;

}

 

Output:

Please enter number of elements

3

Enter the elements one by one

5

3

8

Enter the element to be searched

3

3 is found at the location 2.

 


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!