Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
please help me to resolve a problem with loops

I have to resolve this exercice : Display all the numbers in descending order between 0 and 100, then display hurray each prime number between 100 and zero within the same loop that displays the decreasing eveners.

I did this code :

for($n=100; $n>0; $n-=1 ){
    $tableaunombrepaires[]= $n;
//loop for dividers
for($j=2; $j<=$n/2; $j++) {
    $diviseurs[]= $j;
}
// here we devide 
    foreach($diviseurs as $diviseur){
        $restes[]=$n%$diviseur;    
    }
    if(!(in_array(0,$restes))){
        echo "$n hourrah! \n";
    } 
    else{
        echo "$n \n";
    }
    
}

but it doesn't work help please

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

function isPrime ($n) {
    for ($x = 2; $x < $n; $x++) {
        if($n % $x == 0) {
            return false;
        }
    }
    return true;
}

for($n = 100; $n > 0; $n--) {
    if (isPrime($n)) {
        echo $n . " hourrah! \n";      
    } else {
        echo $n . "\n";
    }
}

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!