include <c - blogestudiantedariomoralesg

Anuncio
repeticion
Poner un while y un do wile al suwich q contiene y opciones
Para while
codigo
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;windows.h&gt;
int k;
main()
{
while(k&gt;=0)
{
printf (&quot;\n menu&quot;);
printf (&quot;\n1. sacar el mayor de 2 numeros&quot;);
printf (&quot;\n2. cacar el mayor de 3 numeros&quot;);
printf (&quot;\n3. conteo del o al 7&quot;);
printf (&quot;\n4. conteo del 3 al 1&quot;);
printf (&quot;\n5. salir&quot;);
printf (&quot;\n escoger opcion&quot;);
scanf (&quot;%d&quot;,&amp;k);
switch (k)
{
case 1:
{
int a,b;
printf (&quot;comprara 2 numeros&quot;);
printf (&quot;\n dame un numero entero, a=&quot;);
scanf(&quot;%d&quot;,&amp;a);
printf (&quot;dame otro numero entero, b=&quot;);
scanf(&quot;%d&quot;,&amp;b);
if (a&gt;b)
printf(&quot;a es mayor&quot;);
else
{
if (b&gt;a)
printf (&quot; b es mayor&quot;);
else
printf (&quot;a=b&quot;);
}
getch();
}
break;
case 2:
{
int a,b,c;
printf (&quot;comparar 3 numeros&quot;);
printf (&quot;\n dame un numero entero, a=&quot;);
scanf(&quot;%d&quot;,&amp;a);
printf (&quot;dame otro numero entero, b=&quot;);
scanf(&quot;%d&quot;,&amp;b);
printf (&quot;dame otro numero entero, c=&quot;);
scanf(&quot;%d&quot;,&amp;c);
if ((a&gt;b)&amp;&amp;(a&gt;c))
printf (&quot;a es mayor&quot;);
else
{
if ((b&gt;a)&amp;&amp;(b&gt;c))
printf (&quot; b es mayor&quot;);
else
{
if ((c&gt;a)&amp;&amp;(c&gt;b))
printf (&quot;c es mayor&quot;);
else
printf(&quot;a=b=c&quot;);
}
}
getch();
}
break;
case 3:
{
int i;
for(i=0;i&lt;8;i++)
printf(&quot;%d&quot;,i);
getch();
}
break;
case 4:
{
int i;
for (i=3;i&gt;0;i--)
printf(&quot;%d&quot;,i);
getch();
}
break;
default:
printf (&quot;para salir dar enter&quot;);
break;
}
getch();
}
}
Im&aacute;genes
Para do while
C&oacute;digo
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;windows.h&gt;
int k;
main()
{
do
{
printf (&quot;\n menu&quot;);
printf (&quot;\n1. sacar el mayor de 2 numeros&quot;);
printf (&quot;\n2. cacar el mayor de 3 numeros&quot;);
printf (&quot;\n3. conteo del o al 7&quot;);
printf (&quot;\n4. conteo del 3 al 1&quot;);
printf (&quot;\n5. salir&quot;);
printf (&quot;\n escoger opcion&quot;);
scanf (&quot;%d&quot;,&amp;k);
switch (k)
{
case 1:
{
int a,b;
printf (&quot;comprara 2 numeros&quot;);
printf (&quot;\n dame un numero entero, a=&quot;);
scanf(&quot;%d&quot;,&amp;a);
printf (&quot;dame otro numero entero, b=&quot;);
scanf(&quot;%d&quot;,&amp;b);
if (a&gt;b)
printf(&quot;a es mayor&quot;);
else
{
if (b&gt;a)
printf (&quot; b es mayor&quot;);
else
printf (&quot;a=b&quot;);
}
getch();
}
break;
case 2:
{
int a,b,c;
printf (&quot;comparar 3 numeros&quot;);
printf (&quot;\n dame un numero entero, a=&quot;);
scanf(&quot;%d&quot;,&amp;a);
printf (&quot;dame otro numero entero, b=&quot;);
scanf(&quot;%d&quot;,&amp;b);
printf (&quot;dame otro numero entero, c=&quot;);
scanf(&quot;%d&quot;,&amp;c);
if ((a&gt;b)&amp;&amp;(a&gt;c))
printf (&quot;a es mayor&quot;);
else
{
if ((b&gt;a)&amp;&amp;(b&gt;c))
printf (&quot; b es mayor&quot;);
else
{
if ((c&gt;a)&amp;&amp;(c&gt;b))
printf (&quot;c es mayor&quot;);
else
printf(&quot;a=b=c&quot;);
}
}
getch();
}
break;
case 3:
{
int i;
for(i=0;i&lt;8;i++)
printf(&quot;%d&quot;,i);
getch();
}
break;
case 4:
{
int i;
for (i=3;i&gt;0;i--)
printf(&quot;%d&quot;,i);
getch();
}
break;
default:
printf (&quot;para salir dar enter&quot;);
break;
}
getch();
}
while (k&gt;2);}
Im&aacute;genes
Descargar