Hackerearth: Linear Search Algorithm Problem

Default :
Source: https://www.hackerearth.com/practice/algorithms/searching/linear-search/tutorial/
code:

/*
hackerearth linear search test

*/
#include<stdio.h>
int main()
{
//long long int sizer=100000;
//long long int A[sizer];

    long long int A[100005];
    int i,n,m;
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++)
    {
        scanf("%d",&A[i]);
    }
    int result=-1;

    for(i=0; i<n; i++)
    {
        if(A[i]==m)
        {
           result=i+1;
        }
    }
    printf("%d",result);
    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *