4 comments:

  1. $N=$_POST["num"];
    $sum=0;
    for($i=1,$k=0;$i<=2*$N-1;$i+=2,$k++)
    {
    if($k%2==0)
    $sum+=$i;
    else
    $sum-=$i;
    }
    echo "$sum";

    ReplyDelete
  2. php
    $num1=$_POST['num'];
    $sum=0;
    for($i=1;$i<=$num1;$i+=4)
    {$sum=$sum+$i;
    }
    $sum1=0;
    for($j=3;$j<=$num1;$j+=4)
    {$sum1=$sum1+$j;
    }
    $result=$sum-$sum1;
    echo"$result";
    ?>

    ReplyDelete
  3. $N=$_POST["n"];
    $sum=0;
    for($j=0,$i=1;$i<=2*$N-1;$j++,$i+=2)
    {
    if($j%2==0)
    $sum+=$i;
    else
    $sum-=$i;
    }
    echo "$sum";

    ReplyDelete
  4. php
    $num=$_post["$s"];
    $total=0;
    for($i=0,$j=1;$j<=2*$s-1;$i++,$j=$j+2)
    {
    if ($i%2==0)
    {
    $total=$total+$j;
    }
    else
    {$total=$total-$j;
    }
    echo"$total";

    ReplyDelete