-
Lenguaje
C
-
Descripción
Programa que pide el número de niveles para mostrar el Triángulo de Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int i, j, n, *buffer, *fila;
printf ("Ingrese el n\243mero de niveles: ");
scanf ("%d", &n);
buffer = (int*) calloc (n+2, sizeof (int));
fila = (int*) calloc (n+2, sizeof (int));
for (j=0; j<n+2; j++)
{
buffer[j] = 0;
fila [j] = 0;
}
for (i=0; i<=n; i++)
{
fila[0] = 1;
fila[i] = 1;
for (j=1; j<=i+1; j++)
fila[j] = buffer[j-1] + buffer[j];
for (j=n-1; j>=i; j--)
printf (" ");
for (j=0; j<=i; j++)
printf ("%5d ", fila[j]);
printf ("\n");
for (j=0; j<n+2; j++)
buffer[j] = fila[j];
}
putchar ('\n');
system ("pause");
return 0;
}
#include <stdlib.h>
int main (void)
{
int i, j, n, *buffer, *fila;
printf ("Ingrese el n\243mero de niveles: ");
scanf ("%d", &n);
buffer = (int*) calloc (n+2, sizeof (int));
fila = (int*) calloc (n+2, sizeof (int));
for (j=0; j<n+2; j++)
{
buffer[j] = 0;
fila [j] = 0;
}
for (i=0; i<=n; i++)
{
fila[0] = 1;
fila[i] = 1;
for (j=1; j<=i+1; j++)
fila[j] = buffer[j-1] + buffer[j];
for (j=n-1; j>=i; j--)
printf (" ");
for (j=0; j<=i; j++)
printf ("%5d ", fila[j]);
printf ("\n");
for (j=0; j<n+2; j++)
buffer[j] = fila[j];
}
putchar ('\n');
system ("pause");
return 0;
}