// Prueba del triangulo de pascal en C
#include <stdio.h>
#include <stdlib.h>
int *CalculateLevel (int Level)
{
int *Result;
Result = (int *) malloc (Level * sizeof (int));
if (Level == 0)
*Result = 1;
if (Level == 1)
{
*Result = 1;
*(Result + 1) = 1;
}
if (Level > 1)
{
int *ResultP = CalculateLevel (Level - 1);
for (int i = 0; i < Level; i++)
{
if (i == 0 || i == Level - 1)
*(Result + i) = 1;
else
*(Result + i) = *(ResultP + i) + *(ResultP + i - 1);
}
}
return (Result);
}
void
DrawPascalTriangle (int Number)
{
if (Number > 20)
{
printf ("Solo se admiten 20 niveles");
}
else
{
for (int i = 0; i < (Number + 1); i++)
{
int *Result = CalculateLevel (i);
for (int j = 0; j < i; j++)
{
printf (" %5d ", *(Result + j));
}
printf ("\n");
}
}
}
int
main ()
{
int Levels;
printf ("Numero de niveles\n");
scanf ("%d", &Levels);
DrawPascalTriangle (Levels);
return 0;
}