Created
September 25, 2023 09:41
-
-
Save 4RSIM3R/75af427490a4787b033dc894f2c5b8ed to your computer and use it in GitHub Desktop.
[PHP] positive negative ration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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