Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function linearSearch($arr, $n , $x){
- for ($i = 0 ; $i < $n ;$i++)
- {
- if($arr[$i] == $x)
- return $i;
- }
- return -1;
- }
- $A = array(17, 3, 45, 8, 29, 12, 56, 4, 23, 9, 31, 5, 48, 27, 1, 15, 36, 19, 7, 50);
- $N = count($A);
- $X = 31;
- // print arr
- for ($i = 0 ; $i < $N; $i++)
- echo $A[$i]." ";
- echo "<br></br>";
- $result = linearSearch($A,$N, $X);
- if($result != -1)
- echo "th value $X is found in $result ";
- else
- echo "the value $X not found " ;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement