All pastes #503473 Raw Edit

pascal triangle

public c v1 · immutable
·published 2007-05-22 21:49 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>void usage (char** argv){      printf ("%s <integer>: output given line of pascal's triangle\n", argv[0]);}int main (int argc, char** argv){  if (argc != 2)     {      usage (argv);      exit (1);    }  int line = atoi (argv[1]);  if (line == 0)    {      usage (argv);      exit (1);    }    int* from = calloc (line + 1, sizeof(int));  int* to = calloc (line + 1, sizeof(int));  *from = 1;  for (int i = 0; i < line; i++) {    to[0] = 1;    for (int j = 1; j < (line + 1); j++) {      to[j] = from[j - 1] + from [j];    }    int* temp = from;    from = to;    to = temp;  }  for (int i = 0; i < line; i++)    printf ("%3i", to[i]);  puts ("\n");}