Skip to content

Instantly share code, notes, and snippets.

@4RSIM3R
Created September 25, 2023 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4RSIM3R/75af427490a4787b033dc894f2c5b8ed to your computer and use it in GitHub Desktop.
Save 4RSIM3R/75af427490a4787b033dc894f2c5b8ed to your computer and use it in GitHub Desktop.
[PHP] positive negative ration
<?php
// negative positive ratio
// anda memiliki sebuah array 'arr' yang berisi : [-1, 1, 2]
// buatlah program untuk menentukan rasio (berupa bilangan pecahan) antara jumlah bilangan negatif dibandingkan bilangan positif
// arr = [-1, 1, 2], maka hasil nya adalah 0.5, karena jumlah bilangan negatif nya 1 dan bilangan positif nya 2 -> 1 / 2 = 0.5
$arr = [-1, -1, 1, 2];
$result1 = 0; // 1
for ($i = 0; $i < count($arr) - 1; $i++) {
# code...
}
echo $result1; // 1
$arr = [-1, -1, 1, 2, -1];
$result2 = 0; // 1.5
echo $result2; // 1.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment