Q:

Write a PHP program to find heights of the top three building in descending order from eight given buildings

0

Write a PHP program to find heights of the top three building in descending order from eight given buildings.

Input:
0 ≤ height of building (integer) ≤ 10,000

Pictorial Presentation:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
  $heights = array();
  while($line = fgets(STDIN)) {
    rtrim($line, "\n");
    array_push($heights, (int)$line);
  }
  rsort($heights);
  print("Heights of the top three buildings:\n");
  echo $heights[0]."\n";
  echo $heights[1]."\n";
  echo $heights[2]."\n";
?>

Sample Output:

Heights of the top three buildings:
45
25
24

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now