BCA Practical 14

Practical 14 : Write a PHP program which excite with the for loop
<html>

  <head>

  <title>Practical : 14</title>

  </head>

  <body>

  <br>

  <br>

  <center>
<?php 
 $no='';

  $odd='';

  $even='';

  

  if(isset($_POST['ok']))

  {

  $no = $_POST['t1'];

  

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

  {

  if($i%2==0)

  {

  $even = $even + $i;

  }

  else

  {

  $odd = $odd + $i;

  } 

  }

  }

  ?>
<form name="f1" method="post">

  <table>
<tr>

  <td>Enter No. :</td>

  <td><input type="text" name="t1" value="<?php echo $no; ?>"></td>

  </tr>
<tr>

  <td>Sum of Odd No.  :</td>

  <td>

  <input type="text" name="t2" value="<?php echo $odd; ?>">

  </td>

  </tr>
<tr>

  <td>Sum of Even No.  :</td>

  <td>

  <input type="text" name="t3" value="<?php echo $even; ?>">

  </td>

  </tr>
<tr>

  <td colspan="2" align="center">

  <input type="submit" name="ok" value="Click Me">

  </td>

  </tr>

  </table>

  </form>

  </center>
</body>

  </html>



EmoticonEmoticon