Friday, 26 June 2015

Sum of the Squares of the first N Natural Numbers

//Tanzila Islam

//Southeast University

//mail : tanzilamohita@gmail.com


<?PHP

  if($_SERVER['REQUEST_METHOD']=="POST")

  {

   $n = $_POST['num'];

 

    $sum = ($n * ($n + 1) * (2 * $n + 1 )) / 6;


    printf("Sum of the series : ");


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

 {

         if ($i != $n)

             printf("%d^2 + ",$i);

         else

             printf("%d^2 = %d ",$i,$sum);

    }


   

}

?>


<form method="post" action="">

Give some input  : <input type="text" name="num" /><br />

<input type="submit" value="Submit" />

</form>





 

No comments:

Post a Comment