Program to print and sum of 1+3+5+14+9+11+13+30+17...n using php

by Sanju 2012-06-28 11:32:42

Program to print and sum of 1+3+5+14+9+11+13+30+17...n using php

To print the numbers


<?php
echo "Print the numbers 1,3,5,14,9,11,13,30,17...n : ";
$sum=0;
for($i=0; $i<=n; $i++)
{
if($i%2==0){

}
else
{
if($i%8==7)
{
$j=$i*2;
echo "$j,";
}
else
{
echo "$i,";
}
}
}
?>


Sum the numbers

<?php
echo "Sum of 1+3+5+14+9+11+13+30+17...n : ";
$sum=0;
for($i=0; $i<=n; $i++)
{
if($i%2==0){

}
else
{
if($i%8==7)
{
$j=$i*2;
}
else
{
$j=$i;
}
$sum=$sum+$j;
}
}
echo $sum;
?>


Tagged in:

1272
like
1
dislike
0
mail
flag

You must LOGIN to add comments