SET OF PROGRAMS

This blog provided "C" programs for beginners. Providing c programs for students.enjoy this blog.this blog include many c programs for engineering students, IT engineering students and programmers this blog is very useful.this blog post daily 1-5 programs for you.this programs use full for devlop games devlops application and much more. This blog programs useful for projects because all programs post with explanations.

Search Bar

Ads Here

Saturday, 23 June 2018

C program for Linear search

Linear search this C program used for search elements easily to use this program and let's enjoy this program
#include<stdio.h>
main()
{
 int i,n,search,flag=0;
 printf("Enter size of array\n");
 scanf("%d",&n);
 int a[n];
    printf("Enter the numbers\n");
    for(i=0;i<n;i++)
    {
     scanf("%d",&a[i]);
    }

    printf("Enter the element to be searched\n");
    scanf("%d",&search);
    for(i=0;i<n;i++)
    {
     if(a[i]==search)
     {
      flag=1;

     }
    }

    if(flag==1)
    {
     printf("Search Successful\n");
    }
    else
    {
     printf("Search is not Successful\n");
    }
}
Output:
Enter size of array
6
Enter the numbers
78
30
35
21
10
-102
Enter the element to be searched
-102
Search Successful
Explanation:
//Coming Soon..

No comments:

Post a Comment