Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

christmas tree

Name: Anonymous 2008-12-24 22:21

(define (christmasTree h)
    (define (foo k)
        (if (< k 1)
            "" (string-append " " (foo (- k 1)))))
    (define (bar k)
        (if (< k 1)
            "\n" (string-append "*" (bar (- k 1)))))
    (define (ct i)
        (if (= i (+ h 1))
            (string-append
                (foo (- h 1))
                (bar 1))
            (string-append
                (foo (- h i))
                (bar (- (* 2 i) 1))
                (ct (+ i 1)))))
    (display (ct 1)))


#;1> (christmasTree 10)
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

Name: Anonymous 2008-12-25 21:30


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M(v,s,c) (v)=malloc((s)); memset((v),(c),(s))
int main(int argc, char **argv) {
  int i,n;
  char *sp,*st;
  if(!argv[1])
    return 1;
  n = atoi(argv[1]);
  M(sp,n,' ');
  M(st,2*(n+2),'*');
  st[0]=0;
  for(i=0;i<n;i++) {
    sp[n-i-1]=0;
    printf("%s%s",sp,st);
    sp[n-i-1]=' ';
    st[i]='*';
    st[i+1]=0;
    printf("%s\n",st);
  }
  sp[n-1]=0;
  printf("%s*\n",sp);
  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List