lundi 5 octobre 2015

Combine two different programms PHP

i want to combine two different programs in the same code but i can't find out how.The program must echo the numbers 1 to 100 but for the multiples of 7 instead of the numbers i want to echo the word "multiseven" and instead of the numbers 5 i want to echo the word "multifive" for the multiples of 5. the code for this is:

<?php 

for($i=1; $i<=100; $i++)    

    if($i%7==0)
    {
    echo ("multiseven")."\n";
    }
    else if($i%5==0)
    {
        echo ("multifive")."\n";
    }
    else
    {
        echo $i ."\n";
    }

?>

The second program must echo the word "common" for the common multiples of 7 and 5.The code of this is:

<?php 

for($i=1; $i<=100; $i++)    

    if($i%7==0 && $i%5==0)
    {
    echo ("Common")."\n";
    }
    else {
        echo $i."\n";
    }

?>

Aucun commentaire:

Enregistrer un commentaire