fork download
  1. <?php
  2. // Baca jumlah angka
  3. fscanf(STDIN, "%d", $n);
  4.  
  5. // Baca deret angka sebagai string
  6. $line = trim(fgets(STDIN));
  7. $numbers = explode(" ", $line);
  8.  
  9. // Inisialisasi
  10. $genap = 0;
  11. $ganjil = 0;
  12.  
  13. foreach ($numbers as $num) {
  14. if ($num % 2 == 0) {
  15. $genap++;
  16. } else {
  17. $ganjil++;
  18. }
  19. }
  20.  
  21. echo "Ganjil: $ganjil\n";
  22. echo "Genap: $genap\n";
  23. ?>
  24.  
Success #stdin #stdout #stderr 0.03s 26052KB
stdin
21846128
stdout
Ganjil: 0
Genap: 1
stderr
PHP Warning:  A non-numeric value encountered in /home/6hCLhd/prog.php on line 14