L
LL
I've cut down the code for Pascal's triangle that someone in this
channel posted few weeks ago in order to understand it. The below code
no longer does Pascal's triangle as the portion of the code is commented
out. Please explain to me the commented out portion. I seem to
understand the recursive logic of it, but don't understand something
else. Thanks.
#include <stdio.h>
#include <stdlib.h>
void pt( long o, long *l ) {
// How does this work? Please explain.
/*
long t = *l;
if ( o )
for ( pt( --o, l ), printf( "1 " ); o; t = l[ --o ] )
printf( "%ld ", l[ o ] = l[ o - 1 ] + t );
puts( "1" );
*/
// I don't know how l[o] is non-zero for o>0 when they are null.
for (;o;--o) {
printf("%ld", l[o-1]); // 0000000001
}
}
int main() {
long o=10, *l;
l=malloc(o*sizeof(*l));
// l[0]=1
*l = 1;
pt(o,l);
free( l );
return 0;
}
channel posted few weeks ago in order to understand it. The below code
no longer does Pascal's triangle as the portion of the code is commented
out. Please explain to me the commented out portion. I seem to
understand the recursive logic of it, but don't understand something
else. Thanks.
#include <stdio.h>
#include <stdlib.h>
void pt( long o, long *l ) {
// How does this work? Please explain.
/*
long t = *l;
if ( o )
for ( pt( --o, l ), printf( "1 " ); o; t = l[ --o ] )
printf( "%ld ", l[ o ] = l[ o - 1 ] + t );
puts( "1" );
*/
// I don't know how l[o] is non-zero for o>0 when they are null.
for (;o;--o) {
printf("%ld", l[o-1]); // 0000000001
}
}
int main() {
long o=10, *l;
l=malloc(o*sizeof(*l));
// l[0]=1
*l = 1;
pt(o,l);
free( l );
return 0;
}