So I'm trying to get this output using a for loop. 1 1 2 1 I just can't get a logic good enough. I need help. Anyone has any idea?
Care to elaborate ? The given snippet produces exactly what you were asking for. If there are any other hidden rules, tell us about them first.
The 1 shouldn't be printed directly through quotes. It should be printed by the logic of the for loop. For eg, you don't print the Fibonacci series by directly putting it into the quotes, do you? It is printed using a logic.
I was asked this question to test my logic. But I couldn't answer it. The best I could get is this: for($i=1; $i<=2; $i++) { for($j=1; $j<=2; $j++) { echo ceil($i/$j)." "; } echo "\n"; } PHP: