New Android apps UniqueKey

Friday 20 February 2015

Linear Search


#include<stdio.h>

main()
{

    int arr[10],i,n,key,c=0;

    printf("Enter the size of an array: ");
    scanf("%d",&n);

    printf("Enter the elements of the array: ");
    for(i=0;i<=n-1;i++)
 {
         scanf("%d",&arr[i]);
    }

    printf("Enter the number to be search: ");
    scanf("%d",&key);
    
 for(i=0;i<=n-1;i++)
 {
         if(arr[i]==key)
   {
             c=1;
             break;
         }
    }
    if(c==0)
         printf("The number is not found");
    else
         printf("The number is found");

    return 0;
}

No comments:

Post a Comment