Advertisement
kadoel

Ganjil

Nov 12th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <!--
  2.  
  3. Function by : Kadoel Noesa
  4. Penggunaan : Ganjil(10)
  5. output : 1-3+5-7+9-11+13-15+17-19
  6.  
  7. -->
  8.  
  9. <html>
  10. <head><title> Ganjil </title></head>
  11. <body>
  12. <?
  13. $n=10;
  14. $a=$n*2;
  15. $b=1;
  16. if ($a%2==0)
  17. {
  18.     echo $b." ";
  19.     for ($s=1; $s<$a-1; $s++)
  20.     {
  21.         echo " - ";
  22.         echo $s+2;
  23.         $s=$s+2;
  24.        
  25.         echo " + ";
  26.         echo $s+2;
  27.         $s=$s+1;
  28.        
  29.         if ($s==$a-4)
  30.         {
  31.             break;
  32.         }
  33.    
  34.     }
  35.    
  36.         echo " - ";
  37.         echo $s+3;
  38. }
  39. ?>
  40. </body>
  41. </html>
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement