Elo, I got this code snippet from an old exam. It's tricky and I need some help figuring out how it prints "007".
#include <stdio.h>
/* Desmond Llewelyns */
int M(int Q);
int main(void)
{
M(9);
return 0;
}
int M(int Q)
{
if(Q>1)
if(M(Q-1)==0)
printf("%03d\n", Q);
return Q-6;
}
It is pretty simple.
Number will be printed only if M(Q-1)
returns 0
and that happens when value of Q
is 7
.
And about the zeros, it is because you are asking printf to print the number in 3 positions printing zeros in the begining. printf("%03d\n", Q);
Read more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With