Click here to Skip to main content
16,020,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys , i have this code .

PHP
<?php
echo "<br>";
$start = 1;
$angka = $_POST[angka];
$a = $angka;
for($i=$start; $i<=$angka; $i++) {
for($j=$start;$j<=$angka;$j=$j+2){
echo $i;
if($j < $angka) echo $a;
}
$a--;
echo '<br>';
}
?>


This is not my expecting result .
First i want the result like this .

-2-4-
1-3-5
-2-4-
1-3-5
-2-4-

The rule is Number of rows and columns follow the number of numbers declared.If the declaration of the number 5, then the results will be displayed are 5 rows and 5 columns like the example above.

What I have tried:

I tried to googling , and ask other forum.
Posted
Updated 6-May-18 5:51am
v2

1 solution

You will not find the answer in Google, because this is a simple logic issue. Look at your requirements:

  • If the row number (starting from 0) is even then print - characters for odd numbers, but print even numbers correctly.
  • If the row number is odd, print - characters for even numbers, but print odd numbers correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900