code is compiled but they show the wrong output
Doubt in the program of linear search
Hi @Tanish
Your loops should run from 0 to n-1
That is
for( i = 0; i < n ; i++ )
You have used i<=n in your code. This will give you the wrong answer since arrays use 0 indexing.
Also your code will fail in case the key element is not present. To prevent this , do not declare the i variable in your search loop again and simply use the one declared above in the beginning of the main( ).