SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    1
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Need help with homework, beginner

    PHP Code:
                  // create a php script that lists out all the numbers that are divisible of 3 up to 100
            //for løkke
          
            
            
    for ($teller=3;$teller<100;$teller+=3) {
                echo 
    $teller." ";
            }
            
            
    //Do the same with an while loop
            
            //while løkke
            
            
    $teller=3;
            while(
    $teller<100){
                echo 
    "$teller ";$teller+=3;
            }
            
            
    //find the average of the numbers (3-100)
            
            
    $alleTall=array(3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99);//gjennomsnitt av tallene
            
    echo array_sum($alleTall)/count($alleTall);
            

            
    //Numbers above 5
            
            
    $liste = array(1,4,8,1,4,10,5,6,2,4,6); //lister ut tallene som er feme ller over. Usikker på om jeg skulle ta med fem eller ikke.
            
    echo $liste[2]." ";
            echo 
    $liste[5]." ";
            echo 
    $liste[6]." ";
            echo 
    $liste[7]." ";
            echo 
    $liste[10]." ";
            
          
    //count up how many numbers that are above  5 and show this
            
            
    function hoyere_enn($arg){
            return 
    $arg 5;}

            
    $nummere = array(1,4,8,1,4,10,5,6,2,4,6);
            
    $filter array_filter($nummere'hoyere_enn');
            
    print_r($filter);
            
           
    // Print array backwards
            
            
    $liste1 = array(1,4,8,1,4,10,5,6,2,4,6);
            
    $listeBaklengs implode(" "array_reverse($liste1));  
            echo 
    $listeBaklengs;
            
           
    // Smallest number in the array.
            
            
    $minste=array(1,4,8,1,4,10,5,6,2,4,6);
            echo 
    min($minste); 

    The language in the coding is Norwegian, tell me if you need me to translate. I hope someone can help me with this, im pretty new to PHP. This is my first homework.


    Thanks

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    For Q1 go and read the manual page on range();

    Come back with a working example, or your best attempt at it and some evidence you have tried something.

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Incidentally, if this is your homework assignment, why is it in a language you cant understand?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,245
    Mentioned
    156 Post(s)
    Tagged
    1 Thread(s)
    @nepz ;

    Are you asking us to validate your assignment or to help you out with an issue in your assignment? As it looks like you did what was requested albeit the only one that looks wrong is
    PHP Code:
            //Numbers above 5 
             
            
    $liste = array(1,4,8,1,4,10,5,6,2,4,6); //lister ut tallene som er feme ller over. Usikker på om jeg skulle ta med fem eller ikke. 
            
    echo $liste[2]." "
            echo 
    $liste[5]." "
            echo 
    $liste[6]." "
            echo 
    $liste[7]." "
            echo 
    $liste[10]." "
    There are better ways to implement that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •