{"id":1293,"date":"2014-03-03T11:05:13","date_gmt":"2014-03-03T16:05:13","guid":{"rendered":"http:\/\/blog.espol.edu.ec\/icm00794\/?p=1293"},"modified":"2026-04-05T17:54:24","modified_gmt":"2026-04-05T22:54:24","slug":"s2eva2003tii_t2-mostrar-un-triangulo-de-pascal","status":"publish","type":"post","link":"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-s2eva10\/s2eva2003tii_t2-mostrar-un-triangulo-de-pascal\/","title":{"rendered":"s2Eva2003TII_T2 Mostrar un tri\u00e1ngulo de Pascal"},"content":{"rendered":"\n<p><em><strong>Ejercicio<\/strong><\/em>: <a href=\"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-2eva10\/2eva2003tii_t2-mostrar-un-triangulo-de-pascal\/\" data-type=\"post\" data-id=\"2863\">2Eva2003TII_T2 Mostrar un tri\u00e1ngulo de Pascal<\/a><\/p>\n\n\n\n<p>Para crear la matriz de Pascal en Python se usa la librer\u00eda Numpy, con lo que se crea un arreglo de tama\u00f1o nxn lleno de ceros.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>1<\/td><td>2<\/td><td>1<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>1<\/td><td><em><strong>3<\/strong><\/em><\/td><td><em><strong>3<\/strong><\/em><\/td><td>1<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>1<\/td><td>4<\/td><td><em><strong>6<\/strong><\/em><\/td><td>4<\/td><td>1<\/td><td>&nbsp;<\/td><\/tr><tr><td>1<\/td><td>5<\/td><td>10<\/td><td>10<\/td><td>5<\/td><td>1<\/td><\/tr><tr><td>\u2026.<\/td><td>\u2026.<\/td><td>\u2026.<\/td><td>\u2026.<\/td><td>\u2026.<\/td><td>\u2026.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Al recorrer la matriz por cada fila <code>f<\/code> y columna <code>c<\/code>, si la posici\u00f3n matriz[f,c] es la primera columna a la izquierda (c==0) o la diagonal (f==c) se escribe 1.<\/p>\n\n\n\n<p>Si la posici\u00f3n de la matriz[f,c] es debajo de la diagonal, se suman los valores de las casilla inmediata superior e izquierda superior.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pascal&#091;f,c] = pascal&#091;f-1,c] + pascal&#091;f-1,c-1]<\/code><\/pre>\n\n\n\n<p>Al terminar el recorrido se tendr\u00e1 la matriz con el tri\u00e1ngulo de Pascal.<\/p>\n\n\n\n<p><strong>Tarea<\/strong>: Convertir el algoritmo a funci\u00f3n.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Algoritmo en Python<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# ICM00794-Fundamentos de Computaci\u00f3n - FCNM-ESPOL\n# 2Eva_IIT2003_T2 Mostrar un tri\u00e1ngulo de Pascal\n# propuesta: edelros@espol.edu.ec\n\nimport numpy as np\n\n# INGRESO\nn = int(input('tama\u00f1o del triangulo: '))\n\n# PROCEDIMIENTO\npascal = np.zeros(shape=(n,n),dtype=int)\nf = 0\nwhile (f&lt;n):\n    c = 0\n    while (c&lt;=f):\n        if (c==0 or c==f):\n            pascal&#x5B;f,c] = 1\n        else:\n            pascal&#x5B;f,c] = pascal&#x5B;f-1,c] + pascal&#x5B;f-1,c-1]\n        c = c+1\n    f = f+1\n\nprint(pascal)\n<\/pre><\/div>\n\n\n<p>resultado del algoritmo en una matriz<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tama\u00f1o del triangulo: 10\n&#091;&#091;  1   0   0   0   0   0   0   0   0   0]\n &#091;  1   1   0   0   0   0   0   0   0   0]\n &#091;  1   2   1   0   0   0   0   0   0   0]\n &#091;  1   3   3   1   0   0   0   0   0   0]\n &#091;  1   4   6   4   1   0   0   0   0   0]\n &#091;  1   5  10  10   5   1   0   0   0   0]\n &#091;  1   6  15  20  15   6   1   0   0   0]\n &#091;  1   7  21  35  35  21   7   1   0   0]\n &#091;  1   8  28  56  70  56  28   8   1   0]\n &#091;  1   9  36  84 126 126  84  36   9   1]]\n&gt;&gt;&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ejercicio: 2Eva2003TII_T2 Mostrar un tri\u00e1ngulo de Pascal Para crear la matriz de Pascal en Python se usa la librer\u00eda Numpy, con lo que se crea un arreglo de tama\u00f1o nxn lleno de ceros. 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 1 &nbsp; &nbsp; &nbsp; &nbsp; 1 2 1 &nbsp; &nbsp; &nbsp; 1 3 3 1 [&hellip;]<\/p>\n","protected":false},"author":8043,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"wp-custom-template-entrada-fp-ejemplos","format":"standard","meta":{"footnotes":""},"categories":[131],"tags":[58,157],"class_list":["post-1293","post","type-post","status-publish","format-standard","hentry","category-fp-s2eva10","tag-ejemplos-python","tag-fundamentos-programacion"],"_links":{"self":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/users\/8043"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/comments?post=1293"}],"version-history":[{"count":3,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1293\/revisions"}],"predecessor-version":[{"id":23664,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/1293\/revisions\/23664"}],"wp:attachment":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/media?parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/categories?post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/tags?post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}