<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Código C++ &#187; Programas</title>
	<atom:link href="http://codigoc.org/cat/programas/feed" rel="self" type="application/rss+xml" />
	<link>http://codigoc.org</link>
	<description>Ayuda para tu tarea en C++</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Centrar texto automáticamente sin gotoxy</title>
		<link>http://codigoc.org/417-centrar-texto-automaticamente-sin-gotoxy</link>
		<comments>http://codigoc.org/417-centrar-texto-automaticamente-sin-gotoxy#comments</comments>
		<pubDate>Sat, 04 Sep 2010 23:34:08 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[cadenas]]></category>
		<category><![CDATA[string.h]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=417</guid>
		<description><![CDATA[Pues si, en este post vamos a hacer un programa en c++ que lee una frase y luego la muestra centrada en la pantalla, todo eso ¡sin usar gotoxy! wow. Bueno, usando gotoxy sería mas fácil, pero este blog promueve el no uso de la librería conio.h (Cómo dejar de usar conio.h) así que lo [...]]]></description>
			<content:encoded><![CDATA[<p>Pues si, en este post vamos a hacer un <strong>programa en c++</strong> que lee una frase y luego la muestra centrada en la pantalla, todo eso ¡<strong>sin usar gotoxy</strong>! wow.</p>
<p>Bueno, usando <em>gotoxy</em> sería mas fácil, pero este blog promueve el no uso de la <strong>librería conio.h</strong> (<a href="http://codigoc.org/274-como-dejar-de-usar-conio-h">Cómo dejar de usar conio.h</a>) así que lo vamos a hacer como les dije.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;iostream&gt;</span>
<span style="color: #339900;">#include&lt;string.h&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">char</span> str<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Una frase: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">getline</span><span style="color: #008000;">&#40;</span>str, <span style="color: #0000dd;">100</span>, <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> numofch <span style="color: #000080;">=</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">40</span><span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span>numofch<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> str<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>A la consola le caben 80 caracteres a lo largo, su mitad son 40; enseguida tenemos que averiguar el numero de caracteres que tiene la frase que se acaba de introducir y dividirlo entre dos. Supongamos que la frase es &#8220;hola&#8221;:</p>
<ol>
<li>&#8216;Hola&#8217; tiene 4 caracteres.</li>
<li>La mitad de la consola es 40.</li>
<li>Si a los 40 le restamos la mitad de los caracteres de la frase, obtenemos el punto en donde debe comenzar la frase para quedar centrada. 40 &#8211; (4/2) = 38</li>
<li>Ahora con un ciclo damos 38 espacios y luego imprimimos la frase.</li>
</ol>
<p>Si quieren utilizar <em>gotoxy</em>, el proceso es el mismo hasta el último paso, donde guardarían el valor obtenido en una variable y luego lo pondrían en el lugar adecuado de la función.</p>
<p>La función <strong>strlen</strong> está en la librería <em>string.h</em> y nos devuelve el número de caracteres que tiene una cadena, viene de <em>string length.</em></p>
<p>A propósito me he dado cuenta que no he hablado casi nada de la librería <a href="http://codigoc.org/tag/string-h">string.h</a>, voy a ver si hago unos cuantos posts sobre ella.</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/417-centrar-texto-automaticamente-sin-gotoxy">Permalink</a> |
<a href="http://codigoc.org/417-centrar-texto-automaticamente-sin-gotoxy#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/417-centrar-texto-automaticamente-sin-gotoxy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Factorial de forma sencilla en C++</title>
		<link>http://codigoc.org/405-factorial-de-forma-sencilla-en-c</link>
		<comments>http://codigoc.org/405-factorial-de-forma-sencilla-en-c#comments</comments>
		<pubDate>Sun, 29 Aug 2010 23:02:34 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[factorial]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=405</guid>
		<description><![CDATA[Ya vimos como calcular el factorial de un número c++ en forma recursiva, sin embargo hay una forma mucho mas fácil de entender y de aplicar (pero menos eficiente). Vamos viendo: Si el factorial de un número es la multiplicación de cada número desde 1 hasta ese número (por ejemplo factorial de 4 = 1*2*3*4 [...]]]></description>
			<content:encoded><![CDATA[<p>Ya vimos como calcular el <strong>factorial de un número c++</strong> en <a href="http://codigoc.org/370-recursividad-aplicada-factorial">forma recursiva</a>, sin embargo hay una forma mucho mas fácil de entender y de aplicar (<em>pero menos eficiente</em>). Vamos viendo:</p>
<p>Si el factorial de un número es la multiplicación de cada número desde 1 hasta ese número (<em>por ejemplo factorial de 4 = 1*2*3*4 = 24</em>), entonces es muy sencillo crear un ciclo de 1 hasta el número pedido en c++ para hacer el cálculo.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> num,fact<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;::FACTORIAL::&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Introduce un numero: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;=</span>num<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        fact <span style="color: #000080;">=</span> fact <span style="color: #000040;">*</span> i<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Su factorial es: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> fact<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>¿Entonces porqué el ciclo empieza en 2? Si comenzara en 1, el proceso para el numero 3 (<em>por poner un ejemplo</em>) sería así:</p>
<ul>
<li>fact = fact * i -&gt; fact = 1 * 1 -&gt; fact = 1</li>
<li>fact = fact * i -&gt; fact = 1 * 2 -&gt; fact = 2</li>
<li>fact = fact * i -&gt; fact = 2 * 3 -&gt; fact = 6</li>
</ul>
<p>Como ven, el primer paso es totalmente innecesario.</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/405-factorial-de-forma-sencilla-en-c">Permalink</a> |
<a href="http://codigoc.org/405-factorial-de-forma-sencilla-en-c#comments">3 comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/405-factorial-de-forma-sencilla-en-c/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Recursividad aplicada: Torres de Hanoi</title>
		<link>http://codigoc.org/397-recursividad-aplicada-torres-de-hanoi</link>
		<comments>http://codigoc.org/397-recursividad-aplicada-torres-de-hanoi#comments</comments>
		<pubDate>Tue, 24 Aug 2010 05:21:06 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[hanoi]]></category>
		<category><![CDATA[recursividad]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=397</guid>
		<description><![CDATA[Este juego matemático es clásico de los problemas de programación. Hoy vamos a ver cómo calcular el número de movimientos necesarios para resolver el juego según el número de discos, de forma recursiva en C++. #include&#60;stdio.h&#62; int hanoi&#40;int n&#41; &#123; if&#40;n==1&#41; return 1; else return 2 * hanoi&#40;n-1&#41; + 1; &#125; int main&#40;&#41; &#123; int [...]]]></description>
			<content:encoded><![CDATA[<p>Este juego matemático es clásico de los <strong>problemas de programación</strong>. Hoy vamos a ver cómo calcular el número de movimientos necesarios para resolver el juego según el número de discos, de <strong>forma recursiva en C++</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">int</span> hanoi<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>n<span style="color: #000080;">==</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">else</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">*</span> hanoi<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> disc, mov<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;::TORRES DE HANOI::<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Numero de discos: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>disc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>Movimientos necesarios: %i<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, hanoi<span style="color: #008000;">&#40;</span>disc<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Otro algoritmo raro. Lo que sabemos es que si tenemos 1 disco el número de movimientos es 1 y que ese es nuestro caso base (<em>si n==1 retorna 1</em>), a partir de ahí el número de movimientos se puede calcular si multiplicamos por dos el número de movimientos para <em>n-1</em> y le sumamos 1, o sea: <em>2 + hanoi(n-1) + 1</em></p>
<ul>
<li>Si son 2 discos, entonces 2 * hanoi(1) + 1 = 2 * 1 + 1 = 3</li>
<li>Si son 3 discos, entonces 2 * hanoi(2) + 1 = 2 * 3 + 1 = 7</li>
<li>etc</li>
</ul>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/397-recursividad-aplicada-torres-de-hanoi">Permalink</a> |
<a href="http://codigoc.org/397-recursividad-aplicada-torres-de-hanoi#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/397-recursividad-aplicada-torres-de-hanoi/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursividad aplicada: Máximo Común Divisor</title>
		<link>http://codigoc.org/393-recursividad-aplicada-maximo-comun-divisor</link>
		<comments>http://codigoc.org/393-recursividad-aplicada-maximo-comun-divisor#comments</comments>
		<pubDate>Sat, 21 Aug 2010 05:05:45 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[recursividad]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=393</guid>
		<description><![CDATA[Ooootro post sobre recursividad, pero no se preocupen ya solo queda este y otro. Esta vez vamos a calcular el máximo común divisor de dos números de forma recursiva en c++. #include&#60;stdio.h&#62; int MCD&#40;int x, int y&#41; &#123; if&#40;y==0&#41; return x; else return MCD&#40;y, x%y&#41;; &#125; int main&#40;&#41; &#123; int num1=0,num2=0; printf&#40;&#34;::MAXIMO COMUN DIVISOR::\n&#34;&#41;; printf&#40;&#34;Introduce [...]]]></description>
			<content:encoded><![CDATA[<p>Ooootro post sobre <strong>recursividad</strong>, pero no se preocupen ya solo queda este y otro. Esta vez vamos a calcular el <strong>máximo común divisor</strong> de dos números de <strong>forma recursiva en c++</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">int</span> MCD<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x, <span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>y<span style="color: #000080;">==</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">return</span> x<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">else</span>
        <span style="color: #0000ff;">return</span> MCD<span style="color: #008000;">&#40;</span>y, x<span style="color: #000040;">%</span>y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> num1<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span>,num2<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;::MAXIMO COMUN DIVISOR::<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Introduce el primer numero: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>num1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Introduce el segundo numero: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>num2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>El resultado es: %i<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, MCD<span style="color: #008000;">&#40;</span>num1, num2<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Este es uno de esos <strong>algoritmos recursivos</strong> raros o, mejor dicho, difíciles de comprender, mi cerebro estuvo un buen rato echando humo tratando de comprender la lógica con que lo armaron y mi conclusión es que funciona de pura rana. Bueno, al final si supe como funciona pero no porque.</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/393-recursividad-aplicada-maximo-comun-divisor">Permalink</a> |
<a href="http://codigoc.org/393-recursividad-aplicada-maximo-comun-divisor#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/393-recursividad-aplicada-maximo-comun-divisor/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursividad aplicada: Serie de Fibonacci</title>
		<link>http://codigoc.org/386-recursividad-aplicada-serie-de-fibonacci</link>
		<comments>http://codigoc.org/386-recursividad-aplicada-serie-de-fibonacci#comments</comments>
		<pubDate>Wed, 18 Aug 2010 05:03:32 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[fibonacci]]></category>
		<category><![CDATA[recursividad]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=386</guid>
		<description><![CDATA[0, 1, 1, 2, 3, 5, 8, 13, 21, &#8230;, la serie de Fibonacci es bastante interesante e incluso aparece en la naturaleza. Comienza con un 0, luego un 1 y a partir de ahí cada número es la suma de los dos siguientes. Eso último nos indica recursividad. Veamos como mostrar n números de [...]]]></description>
			<content:encoded><![CDATA[<p>0, 1, 1, 2, 3, 5, 8, 13, 21, &#8230;, la serie de Fibonacci es bastante interesante e incluso aparece <a href="http://thebatzuk.org/2010/01/fibonacci-en-todas-partes.html">en la naturaleza</a>. Comienza con un 0, luego un 1 y a partir de ahí cada número es la suma de los dos siguientes. Eso último nos indica <strong>recursividad</strong>. Veamos como mostrar <em>n</em> números de la <strong>serie de Fibonacci</strong> de <strong>forma recursiva en C++</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">int</span> fibonacci<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>n<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">return</span> n<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">else</span>
        <span style="color: #0000ff;">return</span> fibonacci<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> fibonacci<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> num<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span>,res<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;::NUMEROS DE FIBONACCI::<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Introduce el numero de numeros: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>i<span style="color: #000080;">&lt;=</span>num<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        res <span style="color: #000080;">=</span> fibonacci<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i  &quot;</span>, res<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Es la primera vez que vemos un la llamada a la función dentro de un ciclo. Eso es porque la función calcula el <em>n-ésimo</em> número de la serie, y para mostrarlos todos tenemos que hacer un ciclo que repita la función tantas veces como sea necesario.</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/386-recursividad-aplicada-serie-de-fibonacci">Permalink</a> |
<a href="http://codigoc.org/386-recursividad-aplicada-serie-de-fibonacci#comments">Un comentario</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/386-recursividad-aplicada-serie-de-fibonacci/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Recursividad aplicada: Convertir Decimal a Binario</title>
		<link>http://codigoc.org/380-recursividad-aplicada-convertir-decimal-a-binario</link>
		<comments>http://codigoc.org/380-recursividad-aplicada-convertir-decimal-a-binario#comments</comments>
		<pubDate>Sun, 15 Aug 2010 04:43:56 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[binario]]></category>
		<category><![CDATA[recursividad]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=380</guid>
		<description><![CDATA[Siguiendo con esto de la recursividad hoy les traigo un nuevo programín, Convertir Decimal a Binario de forma recursiva. #include&#60;stdio.h&#62; void binario&#40;int n&#41; &#123; if &#40;n!=0&#41; &#123; binario&#40;n/2&#41;; printf&#40;&#34;%i&#34;,n%2&#41;; &#125; &#125; int main&#40;&#41; &#123; int num=0; printf&#40;&#34;::CONVERTIR DECIMAL A BINARIO::\n&#34;&#41;; printf&#40;&#34;Introduce un numero: &#34;&#41;;scanf&#40;&#34;%i&#34;,&#38;num&#41;; //Pedir variable num printf&#40;&#34;\t&#34;&#41;;binario&#40;num&#41;;printf&#40;&#34;\n&#34;&#41;; //Llamar la función return 0; &#125; Está [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo con esto de la <strong>recursividad</strong> hoy les traigo un nuevo programín, <strong>Convertir Decimal a Binario</strong> de <strong>forma recursiva</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">void</span> binario<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>n<span style="color: #000040;">!</span><span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        binario<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,n<span style="color: #000040;">%</span><span style="color:#800080;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> num<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;::CONVERTIR DECIMAL A BINARIO::<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Introduce un numero: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//Pedir variable num</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>binario<span style="color: #008000;">&#40;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//Llamar la función</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Está basado en el método que usamos para convertir un número decimal a binario &#8220;a mano&#8221;: dividir el número entre dos hasta que quede 0 y apuntar los residuos del último al primero.</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/380-recursividad-aplicada-convertir-decimal-a-binario">Permalink</a> |
<a href="http://codigoc.org/380-recursividad-aplicada-convertir-decimal-a-binario#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/380-recursividad-aplicada-convertir-decimal-a-binario/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursividad aplicada: Factorial</title>
		<link>http://codigoc.org/370-recursividad-aplicada-factorial</link>
		<comments>http://codigoc.org/370-recursividad-aplicada-factorial#comments</comments>
		<pubDate>Thu, 12 Aug 2010 02:58:55 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[factorial]]></category>
		<category><![CDATA[recursividad]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=370</guid>
		<description><![CDATA[Hola de nuevo, ¿cuánto tiempo pasó? mmm no sé pero bueno&#8230; lo importante es que ya estoy de vuelta y ahora sí me voy a dar el tiempo de actualizar este blog más seguido, pero basta de cosas personales. No me quiero meter en rollos de explicar lo que es la recursividad (googleen y diviértanse [...]]]></description>
			<content:encoded><![CDATA[<p>Hola de nuevo, ¿cuánto tiempo pasó? mmm no sé pero bueno&#8230; lo importante es que ya estoy de vuelta y ahora sí me voy a dar el tiempo de actualizar este blog más seguido, pero basta de cosas personales.</p>
<p>No me quiero meter en rollos de explicar lo que es la <strong>recursividad</strong> (<em>googleen y diviértanse leyendo</em>), lo que quiero es mostrarles algunos ejemplos muy sencillos de dónde podemos aplicar la recursividad. Hoy toca <strong>calcular el factorial</strong> de un numero <strong>de forma recursiva</strong>.</p>
<p>Es el código recursivo más fácil que se pueden encontrar:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">int</span> factorial<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>n<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">else</span>
    <span style="color: #0000ff;">return</span> n <span style="color: #000040;">*</span> factorial<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> num<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;::CALCULAR FACTORIAL::<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Introduce un numero: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%i&quot;</span>,<span style="color: #000040;">&amp;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//Pedir variable num</span>
  <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>El resultado es: %i<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, factorial<span style="color: #008000;">&#40;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//Llama la funcion e imprime resultado</span>
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h3>Explicación</h3>
<p> El caso base es que cuando <em>n</em> valga 1 o 0 retorna un 1, de lo contrario retorna la multiplicación de n * el factorial del numero anterior <em>n-1</em>. Supongamos que introducimos el número 3, cuyo factorial es 6 (<em>3*2*1 = 6</em>).</p>
<ol>
<li><strong>n=3</strong> No entra al caso base. Guardamos para después la operación 3 * factorial(2)</li>
<li><strong>n=2</strong> No entra al caso base. Guardamos para después la operación 2 * factorial(1)</li>
<li><strong>n=1</strong> Entra al caso base. Retorna 1, por lo tanto factorial(1) = 1</li>
<li>Hacemos la última operación que guardamos  2 * factorial(1) = 2 * 1 = 2, por lo tanto factorial(2) = 2</li>
<li>Hacemos la siguiente operación que guardamos  3 * factorial(2) = 3 * 2 = 6</li>
<li><strong>El factorial es 6</strong></li>
</ol>
<p>¡Uh que fácil!</p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2010. |
<a href="http://codigoc.org/370-recursividad-aplicada-factorial">Permalink</a> |
<a href="http://codigoc.org/370-recursividad-aplicada-factorial#comments">4 comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/370-recursividad-aplicada-factorial/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Histograma con números aleatorios y asteriscos</title>
		<link>http://codigoc.org/349-histograma-con-numeros-aleatorios-y-asteriscos</link>
		<comments>http://codigoc.org/349-histograma-con-numeros-aleatorios-y-asteriscos#comments</comments>
		<pubDate>Tue, 24 Nov 2009 02:36:57 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[arreglos]]></category>
		<category><![CDATA[rand]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=349</guid>
		<description><![CDATA[Bueno, tal vez el título quedó muy poco descriptivo, pero la idea es pedir un número de personas, luego se le pediría a cada persona su peso pero nosotros solo vamos a generar un número aleatorio en determinado rango. Luego se clasificaría a esas personas en rangos de peso y al final mostrar una tabla [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, tal vez el título quedó muy poco descriptivo, pero la idea es pedir un número de personas, luego se le pediría a cada persona su peso pero nosotros solo vamos a generar un número aleatorio en determinado rango. Luego se clasificaría a esas personas en rangos de peso y al final mostrar una tabla que muestre la frecuencia de cada rango con asteriscos, así:</p>
<p><code>51-60 ***<br />
61-70 **<br />
71-80 ***<br />
80-91 *<br />
91-mas *****</code></p>
<p>El código en C++ sería así:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdlib.h&gt;</span>
<span style="color: #339900;">#include&lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> n,c,c2,peso<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#93;</span>,cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span><span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span>,lim<span style="color: #008080;">;</span>
    <span style="color: #666666;">// n -&gt; numero de personas</span>
    <span style="color: #666666;">// c y c2 para ciclos</span>
    <span style="color: #666666;">// peso[500] arreglo para guardar el peso de las personas</span>
    <span style="color: #666666;">// cat[5] arreglo para guardar el número de personas en cada categoria de peso</span>
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// Inicializa los números aleatorios</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Introduce el número de personas: &quot;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>n<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c<span style="color: #000080;">&lt;=</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span><span style="color: #0000dd;">51</span><span style="color: #000040;">+</span><span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">120</span><span style="color: #000040;">-</span><span style="color: #0000dd;">51</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//guarda un número aleatorio del 51 al 120 en cada elemento del arreglo</span>
        <span style="color: #666666;">// según su valor se aumenta un elemento de nuestro otro arreglo</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span><span style="color: #0000dd;">50</span> <span style="color: #000040;">&amp;&amp;</span> peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">60</span><span style="color: #008000;">&#41;</span>
            cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span><span style="color: #0000dd;">60</span> <span style="color: #000040;">&amp;&amp;</span> peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">70</span><span style="color: #008000;">&#41;</span>
            cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span><span style="color: #0000dd;">70</span> <span style="color: #000040;">&amp;&amp;</span> peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">80</span><span style="color: #008000;">&#41;</span>
            cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span><span style="color: #0000dd;">80</span> <span style="color: #000040;">&amp;&amp;</span> peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">90</span><span style="color: #008000;">&#41;</span>
            cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>peso<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span><span style="color: #0000dd;">90</span><span style="color: #008000;">&#41;</span>
            cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">switch</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">// segun cada caso imprime algo diferente</span>
            <span style="color: #0000ff;">case</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">:</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;51-60<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">case</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">:</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;61-70<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">case</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">:</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;71-80<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">case</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">:</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;81-90<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">case</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">:</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;90-  <span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
        lim<span style="color: #000080;">=</span>cat<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// no podemos usar un arreglo como limite del ciclo (la verdad</span>
                   <span style="color: #666666;">// no se porque), entonces lo pasamos a una variable normal</span>
        <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c2<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>c2<span style="color: #000080;">&lt;=</span>lim<span style="color: #008080;">;</span>c2<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;*&quot;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// detiene la ejecución al final (es como getch();)</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>A propósito, este programa fue una petición especial de un usuario. </p>
<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2009. |
<a href="http://codigoc.org/349-histograma-con-numeros-aleatorios-y-asteriscos">Permalink</a> |
<a href="http://codigoc.org/349-histograma-con-numeros-aleatorios-y-asteriscos#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/349-histograma-con-numeros-aleatorios-y-asteriscos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Como identificar un palíndromo en C++</title>
		<link>http://codigoc.org/341-como-identificar-un-palindromo-en-c</link>
		<comments>http://codigoc.org/341-como-identificar-un-palindromo-en-c#comments</comments>
		<pubDate>Sat, 21 Nov 2009 04:59:55 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[cadenas]]></category>
		<category><![CDATA[medio]]></category>
		<category><![CDATA[string.h]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=341</guid>
		<description><![CDATA[Lo primero que tendríamos que hacer sería quitar los espacios de nuestra cadena. Luego ir comparando, el primer caracter con el último, el segundo con el penúltimo, etc. Si todos los caracteres coinciden, es palíndromo, si no, pues no. #include&#60;string.h&#62; #include&#60;iostream&#62; using namespace std; &#160; int main&#40;&#41; &#123; char cadena&#91;50&#93;,cadenaf&#91;50&#93;=&#123;0&#125;,*parte; int c,len,pal=0; cout&#60;&#60;&#34;Introduce un palíndromo: [...]]]></description>
			<content:encoded><![CDATA[<p>Lo primero que tendríamos que hacer sería quitar los espacios de nuestra cadena. Luego ir comparando, el primer caracter con el último, el segundo con el penúltimo, etc. Si todos los caracteres coinciden, es palíndromo, si no, pues no.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;string.h&gt;</span>
<span style="color: #339900;">#include&lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">char</span> cadena<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">50</span><span style="color: #008000;">&#93;</span>,cadenaf<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">50</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span><span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span>,<span style="color: #000040;">*</span>parte<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">int</span> c,len,pal<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Introduce un palíndromo: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">getline</span><span style="color: #008000;">&#40;</span>cadena,<span style="color: #0000dd;">50</span>,<span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  parte<span style="color: #000080;">=</span><span style="color: #0000dd;">strtok</span><span style="color: #008000;">&#40;</span>cadena,<span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>                  <span style="color: #666666;">//</span>
  <span style="color: #0000dd;">strcat</span><span style="color: #008000;">&#40;</span>cadenaf,parte<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>                    <span style="color: #666666;">// quita los espacios de 'cadena' y</span>
  <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>parte<span style="color: #000080;">=</span><span style="color: #0000dd;">strtok</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>,<span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>  <span style="color: #666666;">// guarda el resultado en 'cadenaf'</span>
    <span style="color: #0000dd;">strcat</span><span style="color: #008000;">&#40;</span>cadenaf,parte<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>                <span style="color: #666666;">//</span>
&nbsp;
  len<span style="color: #000080;">=</span><span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>cadenaf<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c<span style="color: #000080;">&lt;=</span>len<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>cadenaf<span style="color: #008000;">&#91;</span>len<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #000040;">-</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">==</span>cadenaf<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #666666;">// comparación del primer caracter con el </span>
      pal<span style="color: #000040;">++</span><span style="color: #008080;">;</span>                        <span style="color: #666666;">// último, el segundo con el penúltimo, etc</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pal<span style="color: #000080;">==</span>len<span style="color: #008000;">&#41;</span> <span style="color: #666666;">// si todos las caracteres coinciden, sí es palíndromo</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Sí es palíndromo!&quot;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">else</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;No es palíndromo&quot;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #ff0000; font-style: italic;">/*Creado por THEbatzuk*/</span></pre></div></div>

<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2009. |
<a href="http://codigoc.org/341-como-identificar-un-palindromo-en-c">Permalink</a> |
<a href="http://codigoc.org/341-como-identificar-un-palindromo-en-c#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/341-como-identificar-un-palindromo-en-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ordenar arreglo de manera ascendente o descendente (burbuja)</title>
		<link>http://codigoc.org/333-ordenar-arreglo-de-manera-ascendente-o-descendente-burbuja</link>
		<comments>http://codigoc.org/333-ordenar-arreglo-de-manera-ascendente-o-descendente-burbuja#comments</comments>
		<pubDate>Fri, 20 Nov 2009 04:30:24 +0000</pubDate>
		<dc:creator>THEbatzuk</dc:creator>
				<category><![CDATA[Programas]]></category>
		<category><![CDATA[arreglos]]></category>
		<category><![CDATA[burbuja]]></category>
		<category><![CDATA[funciones]]></category>

		<guid isPermaLink="false">http://codigoc.org/?p=333</guid>
		<description><![CDATA[Programa que lee un arreglo de 10 números y los ordena con el método de la burbuja de manera ascendente o descendente según se elija. Para esto utiliza una función que recibe el arreglo y la varible &#8216;ord&#8217; (1=asc, 2=desc), luego utiliza otra función para imprimirlo. #include&#60;iostream&#62; using namespace std; &#160; int ordenar&#40;int&#91;&#93;,int&#41;; int imprimir&#40;int&#91;&#93;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Programa que <strong>lee un arreglo</strong> de 10 números y los <strong>ordena con el método de la burbuja</strong> de manera <strong>ascendente o descendente</strong> según se elija. Para esto utiliza una función que recibe el arreglo y la varible &#8216;ord&#8217; (1=asc, 2=desc), luego utiliza otra función para imprimirlo.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> ordenar<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span>,<span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> imprimir<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> c,lista<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">9</span><span style="color: #008000;">&#93;</span>,ord<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">9</span><span style="color: #008080;">;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Numero &quot;</span><span style="color: #000080;">&lt;&lt;</span>c<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>lista<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Ascendente 1<span style="color: #000099; font-weight: bold;">\n</span>Descendente 2<span style="color: #000099; font-weight: bold;">\n</span>--&gt; Opción: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>ord<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>ord<span style="color: #000080;">==</span><span style="color: #0000dd;">1</span> <span style="color: #000040;">||</span> ord<span style="color: #000080;">==</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    ordenar<span style="color: #008000;">&#40;</span>lista,ord<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    imprimir<span style="color: #008000;">&#40;</span>lista<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> ordenar<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> lista<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span>,<span style="color: #0000ff;">int</span> ord<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> c1,c2,aux<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c1<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c1<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">9</span><span style="color: #008080;">;</span>c1<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c2<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c2<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">9</span><span style="color: #008080;">;</span>c2<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>ord<span style="color: #000080;">==</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          aux<span style="color: #000080;">=</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
          lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
          lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span>aux<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
      <span style="color: #0000ff;">else</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          aux<span style="color: #000080;">=</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
          lista<span style="color: #008000;">&#91;</span>c2<span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span>lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
          lista<span style="color: #008000;">&#91;</span>c2<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span>aux<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> imprimir<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> lista<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">int</span> c<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>c<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>c<span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">9</span><span style="color: #008080;">;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>lista<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; &quot;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #0000dd;">cin</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #ff0000; font-style: italic;">/*Creado por THEbatzuk*/</span></pre></div></div>

<hr />
<p><small>Post escrito en <a href="http://codigoc.org">Código C++</a> © 2009. |
<a href="http://codigoc.org/333-ordenar-arreglo-de-manera-ascendente-o-descendente-burbuja">Permalink</a> |
<a href="http://codigoc.org/333-ordenar-arreglo-de-manera-ascendente-o-descendente-burbuja#comments">Sin comentarios</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://codigoc.org/333-ordenar-arreglo-de-manera-ascendente-o-descendente-burbuja/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
