Stair-climbing puzzle: Difference between revisions

→‎{{header|C}}: Adapted C++ version into something that will work with classic K&R too
m (→‎{{header|C++}}: whitespace)
(→‎{{header|C}}: Adapted C++ version into something that will work with classic K&R too)
Line 58:
 
=={{header|C}}==
<lang c>void step_up()
The same solution of the [[Stair Climbing#C%2B%2B|C++]] code can be used; the initial declaration of a variable inside a for loop is C99.
{
while (!step()) {
step_up();
}
}</lang>
 
The following uses a variable and is a bit longer, but avoids a possible stack overflow:
<lang c>void step_up()
{
int i = 0;
 
while (i < 1) {
if (step()) {
++i;
} else {
--i;
}
}
}</lang>
 
=={{header|C++}}==
Anonymous user