tag:blogger.com,1999:blog-15114595463155908682024-03-13T12:14:41.867-07:00Introducción a la programaciónAprendiendo a Programar desde 0.Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-1511459546315590868.post-29696096915950268732012-04-26T09:54:00.001-07:002012-04-30T03:48:01.946-07:00Ejercicio con matrices y bucles en Lenguaje C<u><b><span style="font-family: "Courier New",Courier,monospace;">Caso Práctico</span></b></u><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Tenemos guardada en una matriz los alumnos de una escuela. Sabiendo que hay 3 cursos distintos, 5 alumnos por curso y que cada alumno tiene 2 asignaturas, se pide:<br /><br />1. Pedir por teclado las notas que ha sacado cada alumno en cada asignatura y de cada curso.<br /><br />2. Decir cual es la nota media de un determinado curso.<br /><br />3. Decir cuántos aprobados y suspensos hay en una determinada asignatura en un determinado curso.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">int main()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{<br /><br />float escuela[3][5][2];<br />int c,al,as,i,j,menu,asignatura,pos=0;<br />float media=0;<br />float aprobados=0;<br />float suspensos=0;<br /><br />printf("PROGRAMA ESCUELA\n\n");<br />printf("================\n\n");<br /><br />for(c=1;c<4;c++)<br />{<br /> printf("CURSO %d:\n",c);<br /> for(al=1;al<6;al++)<br /> {<br /> printf(" ALUMNO %d:\n",al);<br /> for(as=1;as<3;as++)<br /> { <br /> printf(" Introduce la nota de la Asignatura %d: ",as);<br /> scanf("%f",&escuela[c-1]</span><span style="font-family: "Courier New",Courier,monospace;">[al-1][as-1]);</span> <span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br /><br /> }<br /><br />}<br /><br />printf("\n\n");<br /><br />printf("De que curso quiere saber la nota media? [1,2,3]</span> ");<br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&menu);<br /><br />switch (menu){<br /><br /> case 1:<br /> for(i=0;i<5;i++)</span><br />
{<br />
<span style="font-family: "Courier New",Courier,monospace;">for(j=0;j<2;j++)<br /> {<br /> media += escuela[0][i][j];<br /> }<br /> }<br /> printf("La nota media del Curso 1 es %.2f\n\n\n",media/10);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">break;<br /><br /> case 2:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;">for(i=0;i<5;i++)</span><br />
{<br />
<span style="font-family: "Courier New",Courier,monospace;">for(j=0;j<2;j++)<br />
{<br />
media += escuela[1][i][j];<br />
}<br />
}<br />
printf("La nota media del Curso 2 es %.2f\n\n\n",media/10);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> case 3:<br /> </span><span style="font-family: "Courier New",Courier,monospace;">for(i=0;i<5;i++)</span><br />
{<br />
<span style="font-family: "Courier New",Courier,monospace;">for(j=0;j<2;j++)<br />
{<br />
media += escuela[2][i][j];<br />
}<br />
}<br />
printf("La nota media del Curso 3 es %.2f\n\n\n",media/10);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">break;</span><br />
}<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Aprobados y Suspensos. Seleccione el Curso [1,2,3]</span>");<br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&menu);<br /><br />switch (menu){<br /><br /> case 1:<br /> printf("De que asignatura?[1,2]");<br /> scanf("%d",&asignatura);<br /> if(asignatura==1)<br /> {<br /> for(i=0;i<5;i++)<br /> {<br /> if(escuela[0][i][0]>=5)<br /> {<br /> aprobados++;<br /> }<br /> else<br /> {<br /> suspensos++;<br /> }<br /> }<br /> printf("En la Asignatura 1 del Curso 1 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br /> }<br /> else<br /> {<br /> </span><span style="font-family: "Courier New",Courier,monospace;">for(i=0;i<5;i++)<br />
{<br />
if(escuela[0][i][1]>=5)<br />
{<br />
aprobados++;<br />
}<br />
else<br />
{<br />
suspensos++;<br />
}<br />
</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br />
printf("En la Asignatura 2 del Curso 1 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br />
}<br /> break;<br /><br /> </span><span style="font-family: "Courier New",Courier,monospace;">case 2:<br />
printf("De que asignatura?[1,2]");<br />
scanf("%d",&asignatura);<br />
if(asignatura==1)<br />
{<br />
for(i=0;i<5;i++)<br />
{<br />
if(escuela[1][i][0]>=5)<br />
{<br />
aprobados++;<br />
}<br />
else<br />
{<br />
suspensos++;<br />
}<br />
</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br />
printf("En la Asignatura 1 del Curso 2 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br />
}<br />
else<br />
{<br />
</span><span style="font-family: "Courier New",Courier,monospace;">for(i=0;i<5;i++)<br />
{<br />
if(escuela[1][i][1]>=5)<br />
{<br />
aprobados++;<br />
}<br />
else<br />
{<br />
suspensos++;<br />
}<br />
</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br />
printf("En la Asignatura 2 del Curso 2 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br />
}<br />
break;<br /><br /> </span><span style="font-family: "Courier New",Courier,monospace;">case 3:<br />
printf("De que asignatura?[1,2]");<br />
scanf("%d",&asignatura);<br />
if(asignatura==1)<br />
{<br />
for(i=0;i<5;i++)<br />
{<br />
if(escuela[2][i][0]>=5)<br />
{<br />
aprobados++;<br />
}<br />
else<br />
{<br />
suspensos++;<br />
}<br />
</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br />
printf("En la Asignatura 1 del Curso 3 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br />
}<br />
else<br />
{<br />
</span><span style="font-family: "Courier New",Courier,monospace;">for(i=0;i<5;i++)<br />
{<br />
if(escuela[2][i][1]>=5)<br />
{<br />
aprobados++;<br />
}<br />
else<br />
{<br />
suspensos++;<br />
}<br />
</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }<br />
printf("En la Asignatura 2 del Curso 3 hay %.0f aprobados y %.0f suspensos\n\n",aprobados,suspensos);<br />
}<br />
break;<br />}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">system("PAUSE");<br /><br />}</span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com2tag:blogger.com,1999:blog-1511459546315590868.post-90702475294294009562012-04-26T08:37:00.001-07:002012-04-26T08:37:29.532-07:00Sumar las filas y columnas de una matriz en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">El ejercicio consiste en realizar una matriz de 5x4 elementos y sumar fila por fila y columna por columna, guardando los resultados en dos vectores, uno vertical para las filas, y otro horizontal para las columnas.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Ejemplo:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><b> MATRIZ</b> <b>RESULTADO FILAS </b></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">5 6 7 2 3 23</span><br />
<span style="font-family: "Courier New",Courier,monospace;">4 2 1 0 6 13</span><br />
<span style="font-family: "Courier New",Courier,monospace;">3 2 7 6 5 23</span><br />
<span style="font-family: "Courier New",Courier,monospace;">7 8 5 2 1 23</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">19 18 20 10 15 <b><<-- RESULTADO COLUMNAS</b></span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">int main()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{<br /><br />int matriz[4][5];<br />int horizontal[5];<br />int vertical[4];<br />int fila,columna;<br />int suma=0;<br />int i;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /><span style="color: #3d85c6;">/*Bucle que registra los numeros introducidos de teclado*/</span><br />
</span><span style="font-family: "Courier New",Courier,monospace;">for(fila=0;fila<4;fila++)<br />{<br /> for(columna=0;columna<5;columna++)<br /> {<br /> printf("Introduce un numero para la posicion %d,%d: ",fila,columna);<br /> scanf("%d",&matriz[fila][columna]);<br /> }<br />}<br /><br /><span style="color: #3d85c6;">/*Bucle que suma las filas y registra el resultado en el vector vertical*/</span><br />for(fila=0;fila<4;fila++)<br />{<br /> suma=0;<br /> for(columna=0;columna<5;columna++)<br /> {<br /> suma+=matriz[fila][columna];<br /> }<br /> vertical[fila]=suma;<br />}<br /><br /><span style="color: #3d85c6;">/*Recorre el vector vertical y muestra los resultados*/</span><br />for(i=0;i<4;i++)<br />{<br /> printf("%d\n",vertical[i]);<br />}<br /><br /><span style="color: #3d85c6;">/*Bucle que suma las columnas y registra el resultado en el vector horizontal*/</span><br />for(columna=0;columna<5;columna++)<br />{<br /> suma=0;<br /> for(fila=0;fila<4;fila++)<br /> {<br /> suma+=matriz[fila][columna];<br /> }<br /> horizontal[columna]=suma;<br />}<br /><br />/<span style="color: #3d85c6;">*Recorre el vector horizontal y muestra los resultados*/</span><br />for(i=0;i<5;i++)<br />{<br /> printf("%d",horizontal[i]);<br />}<br />system("PAUSE");<br />}<br /></span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com61tag:blogger.com,1999:blog-1511459546315590868.post-622240050537507842012-04-24T15:31:00.000-07:002012-04-24T15:31:01.906-07:00Calcular el día de la semana a partir de una fecha en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">Para calcular el día de la semana (Lunes, Martes, Miércoles...) a partir de una fecha del tipo 02/03/2010, hay que hacer uso del siguiente algoritmo. </span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix7pDwapP50GDwWiHKHtb_XWfUw5q5O0ZHd7vKMWhsEgJR569lbagZM5pp8WAvRSCaL7J6a_gjQnO4-doSYaFI75IrKYICOVvSyYheAq-CvqbHbCNyE629w74w3OdoCD9ss9AUQZFwP38/s1600/d47d6ff29a1f806790d559d8d7e08c76.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix7pDwapP50GDwWiHKHtb_XWfUw5q5O0ZHd7vKMWhsEgJR569lbagZM5pp8WAvRSCaL7J6a_gjQnO4-doSYaFI75IrKYICOVvSyYheAq-CvqbHbCNyE629w74w3OdoCD9ss9AUQZFwP38/s1600/d47d6ff29a1f806790d559d8d7e08c76.png" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">Donde:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">d = día de la semana</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">A = Año</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">DM = Días transcurridos hasta antes del primer día del mes</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">D = Día</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">% = Módulo</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">En primer lugar debemos tener en cuenta si el año es bisiesto o no. Por lo que para calcular el DM%7 deberemos usar una tabla u otra:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<table class="wikitable"><tbody>
<tr><td style="color: red; font-family: "Courier New",Courier,monospace;"><b>Meses</b></td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">E</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">F</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">M</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">A</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">M</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">J</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">J</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">A</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">S</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">O</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">N</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">D</td>
</tr>
<tr>
<td style="color: red; font-family: "Courier New",Courier,monospace;"><b>Año regular</b></td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">0</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">3</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">3</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">6</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">1</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">4</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">6</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">2</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">5</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">0</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">3</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">5</td>
</tr>
<tr>
<td style="color: red; font-family: "Courier New",Courier,monospace;"><b>Año bisiesto</b></td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">0</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">3</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">4</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">0</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">2</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">5</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">0</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">3</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">6</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">1</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">4</td>
<td style="color: red; font-family: "Courier New",Courier,monospace;">6</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">Vamos a realizar el programa en C:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">{<br /><br /><span style="color: #3d85c6;">//Declaracion de vectores y variables</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">int regular[]={0,3,3,6,1,4,6,2,5,0,3,5};</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">int bisiesto[]={0,3,4,0,2,5,0,3,6,1,4,6};</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">int d,m,a;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span></div>
<div class="separator" style="clear: both; color: #3d85c6; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">//Para simplificar el algoritmo vamos a dividirlo en partes más pequeñas</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><br />int result1,result2,result3,result4,result5;<br /><br />printf("Introduce un dia de la semana en numero: ");</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&d);</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un mes en numero: ");</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&m);</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un anyo en numero: ");</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&a);</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span></div>
<div class="separator" style="clear: both; color: #3d85c6; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">//comprobamos primero si el año es bisiesto o es regular</span></div>
<div class="separator" style="clear: both; color: #3d85c6; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">//si es bisiesto, asignamos a m la posición del vector bisiesto -1</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">//si es regular, asignamos a m la posición del vector regular -1</span><br /><br />if((a%4==0) && !(a%100==0))</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">{</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"> m=bisiesto[m-1];</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">}</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">else if (a%400==0)</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">{</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"> m=bisiesto[m-1];</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">}</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">else</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">{</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"> m=regular[m-1];</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">}</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">//Resolvermos la fórmula poco a poco</span><br /><br />result1=(a-1)%7;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">result2=(a-1)/4;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">result3=(3*(((a-1)/100)+1))/4;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">result4=(result2-result3)%7;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">result5=d%7;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">d=(result1+result4+m+result5)%7;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">//resuelto el dia, con un switch case mostramos en pantalla lo que corresponda.</span><br /><br />switch(d)</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;">{<br /> case 0:<br /> printf("Domingo\n");<br /> break;<br /> case 1:<br /> printf("Lunes\n");<br /> break;<br /> case 2:<br /> printf("Martes\n");<br /> break;<br /> case 3:<br /> printf("Miercoles\n");<br /> break;</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"> case 4:<br /> printf("Jueves\n");</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New",Courier,monospace;"> break;<br /> case 5:<br /> printf("Viernes\n");<br /> break;<br /> case 6:<br /> printf("Sabado\n");<br /> break;<br />}<br />system("PAUSE");<br /><br />}</span></div>
<table class="wikitable"><tbody>
<tr><td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
</tr>
<tr>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
</tr>
<tr>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td>
<td style="text-align: center;"><br /></td><td style="text-align: center;"><br /></td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td><td style="text-align: left;"> </td></tr>
</tbody></table>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com5tag:blogger.com,1999:blog-1511459546315590868.post-66141141117866562202012-04-23T13:19:00.000-07:002012-04-23T13:22:34.188-07:00Calcular la letra del DNI en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">La letra del DNI es una técnica utilizada para evitar los errores al introducir los 8 números de un DNI. </span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Se usan 23 letras del abecedario para el DNI que se encuentran ordenadas en una tabla específicamente así:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">0=T, 1=R, 2=W, 3=A, 4=G, 5=M, 6=Y, 7=F, 8=P, 9=D, 10=X, 11=B, 12=N, 13=J, 14=Z, 15=S, 16=Q, 17=V, 18=H, 19=L, 20=C, 21=K, 22=E.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Cada letra se corresponde con un número.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">La técnica para calcular el DNI es la siguiente:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">- Se divide el nº de DNI entre 23.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">- El resto de la división, corresponderá con la letra de ese DNI.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Así si tecleas tu DNI y te equivocas en un número, el programa compara la letra que has introducido con la que debería tener ese número. Si no coinciden, el programa te avisa.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Eso es lo que vamos a crear en C, un programa que calcule la letra de un DNI y lo compare con la letra introducida por el usuario.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Metemos en un vector las 23 letras usadas en el DNI en el orden especificado anteriormente*/</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">char letras[]={'T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E'};</span><br />
<span style="font-family: "Courier New",Courier,monospace;">int dninumero;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">char letra; </span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce el numero de tu DNI (sin letra): ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&dninumero);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce la letra de tu DNI: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%c",&letra);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Comparamos la letra introducida por el usuario con la calculada por el programa (resto de dividir el DNI entre 23)*/</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">if(letra==letras[dninumero%23])</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El DNI es correcto");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">else</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El DNI NO es correcto");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">} </span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com6tag:blogger.com,1999:blog-1511459546315590868.post-57786312005428385152012-04-22T11:27:00.000-07:002012-04-22T11:30:09.179-07:00Calculadora básica en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">Vamos a crear una sencilla calculadora en C, con un pequeño menú que nos permita seleccionar si deseamos sumar, restar, multiplicar o dividir. Y nos pida dos números con los que operar.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">También añadiremos en el menú una opción para Salir.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Empezamos...</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int eleccion,operador1,operador2;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Empezamos usando un bucle do while para que el programa se ejecute hasta que el usuario seleccione la opcion 5*/</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">do</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;">system("CLS"); <span style="color: #3d85c6;">//Limpia la pantalla en cada nueva operación.</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("CALCULADORA\n\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("1. Suma\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("2. Resta\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("3. Multiplicacion\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("4. Division\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("5. Salir\n\n");</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&eleccion);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Usamos un switch como altenativa multiple para ejecutar la parte correspondiente a la elección del usuario*/</span> </span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">switch(eleccion)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> case 1:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Introduce otro numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Resultado: %d\n",operador1+operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> case 2:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Introduce otro numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Resultado: %d\n",operador1-operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> case 3:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Introduce otro numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Resultado: %d\n",operador1*operador2);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> case 4:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Introduce otro numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> scanf("%d",&operador2);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: #3d85c6;">/*Ponemos la condicion de que no se pueda dividir entre 0 ya que de lo contrario el programa dará error*/</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if(operador2==0)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("No se puede dividir entre 0, intentalo otra vez...\n ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> else</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf(Resultado: %d\n",operador1/operador2); </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> case 5:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("Saliendo...\n\n");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">system("PAUSE");</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Cuando el usuario selecciona la opción 5, el bucle termina y se cierra el programa*/</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">}while(!(eleccion==5));</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">} </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<br />
<br />
<br />Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com14tag:blogger.com,1999:blog-1511459546315590868.post-76486771901037925232012-04-22T03:23:00.002-07:002012-04-22T03:27:21.107-07:00Comprobar si un número es primo en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">Un número primo es aquel que solo es divisible entre 1 y él mismo.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Con lo cual solo tiene 2 divisores.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Así que tendremos que usar el ejercicio anterior de calcular los divisores de un número, y comprobar que solo sean dos para que el número sea primo.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int num1,i,a;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">a=0; <span style="color: #3d85c6;">*/Esta variable la vamos a usar para contar los divisores del número introducido, la inicializamos a 0*/</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&num1);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">for(i=1;i<=num1;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if(num1%i==0)<span style="color: #3d85c6;"> // si num1 módulo de i es 0, incrementamos a en 1.</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"> a++;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">if(a==2); <span style="color: #3d85c6;">/*Si al final del bucle, a vale 2, el número es primo, porque tiene solamente 2 divisores.</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El número es primo");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">else</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El número no es primo"); </span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<br />Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com68tag:blogger.com,1999:blog-1511459546315590868.post-81444684270157914642012-04-22T01:52:00.000-07:002012-04-22T03:31:02.422-07:00Comprobar si un año es bisiesto o regular en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">Para que un año sea bisiesto se deben cumplir 3 condiciones:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">1. <u>Que el año sea múltiplo de 4</u>. Es decir, que al dividirlo entre 4 el resto de 0.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">2. <u>Que el año NO sea múltiplo de 100</u>. Irónico ya que el propio 100 es múltiplo de 4, con lo que esta condición contradice a la primera aunque luego lo resolveremos.</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">3. Para liarlo aún más, <u>un año también es bisiesto si es múltiplo de 400</u>, aunque el propio 400 sea múltiplo de 100 que ya se está contradiciendo con la condición 2. </span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Con esto tenemos que:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">Los años 4,8,12,16... son bisiestos.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Los años 100,200,300,500... no son bisiestos.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Los años 400,800,1200,1600... son bisiestos. </span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">Pues vamos a hacer el programa que lo resuelva todo.</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">int num1;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&num1);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="background-color: #3d85c6;"><span style="background-color: white;"><span style="color: #3d85c6;">//Las dos primeras condiciones: Si num1 es múltiplo de 4 y NO es múltiplo de 100</span></span></span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">if((num1%4==0) && !(num1%100==0))</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El año es bisiesto");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">//La tercera condicion: Si num1 es múltiplo de 4</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">else if (num1%400==0)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El año es bisiesto");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">else <span style="color: #3d85c6;">// Todos los demás no son bisiestos</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("El año NO es bisiesto");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com11tag:blogger.com,1999:blog-1511459546315590868.post-67797061969781848302012-04-22T01:37:00.000-07:002012-04-22T01:37:38.455-07:00Calcular los divisores de un número en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">Al dividir un número por su divisor, el resto de la división debe ser 0. Para ello usaremos en la función el operador Módulo de(%). </span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int num1,i; <span style="color: #3d85c6;">//Declaramos las variables de tipo entero</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: ");</span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&num1); <span style="color: #3d85c6;">//Guardamos el número introducido por el usuario en la variable num1</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Con un bucle for, recorremos todos los números desde el 1 hasta el introducido por el usuario para comprobar uno a uno si es dividor de este.</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">for(i=1;i<=num1;i++) </span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if(num1%i==0) <span style="color: #3d85c6;">//La condición es que el numero dividido entre num1 de como resto 0</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("%d, es divisor de %d \n",i,num1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">} </span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com31tag:blogger.com,1999:blog-1511459546315590868.post-68493551564371060332012-04-21T01:10:00.000-07:002012-04-21T01:10:36.732-07:00Escribir los números pares hasta un número dado en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int num1,i; <span style="color: #3d85c6;">//Declaramos dos variables, una para pedir un numero y la otra para llevar la cuenta del bucle</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: "); <span style="color: #3d85c6;">//Pedimos un número de teclado</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&num1); <span style="color: #3d85c6;">//Lo guardamos en la variable num1</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">/*Usamos un bucle for con los siguientes parámetros:</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">Inicializamos i en 2, en cada paso del bucle, i se incrementará en lo que ya tuviera + 2 (2,4,6,8...). El bucle se ejecutará mientras sea menor o igual que el número que hemos introducido de teclado*/</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;"> </span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">for (i=2;i<=num1;i+=2)<span style="color: #3d85c6;"> </span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("%d \n", i); <span style="color: #3d85c6;">//Mostramos lo que vale i en cada paso del bucle</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">system("PAUSE");</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">} </span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-17586581859925329172012-04-21T00:59:00.000-07:002012-04-21T00:59:20.114-07:00Cuenta atrás desde un número en Lenguaje C<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int num1; <span style="color: #3d85c6;">//Declaración de variable de tipo entero</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">printf("Introduce un numero: "); <span style="color: #3d85c6;">//Pedimos un numero de teclado</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;">scanf("%d",&num1);<span style="color: #9fc5e8;"> <span style="color: #3d85c6;">//Guardamos el numero en la variable num1</span></span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: #3d85c6;">//Usamos un bucle Do While, para que se ejecute al menos una vez</span> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">do{ </span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> printf("%d\n",num1); <span style="color: #3d85c6;">//Muestra en pantalla el numero introducido y lo decrementa en 1.</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"> num--;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">}while (num1 != 0); <span style="color: #3d85c6;">//Todo esto lo realiza mientras num1 no sea 0. En el momento que llega a 0, el bucle termina.</span></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">system("PAUSE";</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">} </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com7tag:blogger.com,1999:blog-1511459546315590868.post-10976993147192534902012-04-21T00:48:00.000-07:002012-04-21T00:50:02.383-07:00Resolver el mayor de dos números en Lenguaje C.<div style="font-family: "Courier New",Courier,monospace;">
{</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
int num1, num2; <span style="color: #3d85c6;">//Declaramos dos variables de tipo entero.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
printf("Introduce un numero: "); <i style="color: #3d85c6;">//Pedimos un numero de teclado.</i></div>
<div style="font-family: "Courier New",Courier,monospace;">
scanf("%d",&num1); <span style="color: #3d85c6;">//Guardamos el numero en la variable num1.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
printf("Introduce otro numero: "); <span style="color: #3d85c6;">//Pedimos otro numero de teclado.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
scanf("%d",&num2); <span style="color: #3d85c6;">//Lo guardamos en la variable num2.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
if(num1 > num2) <span style="color: #3d85c6;">//Comparamos, si num1 es mayor que num2...</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
{ </div>
<div style="font-family: "Courier New",Courier,monospace;">
printf("El mayor es %d \n",num1); <span style="color: #3d85c6;">//Escribimos que el mayor es num1.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
}</div>
<div style="font-family: "Courier New",Courier,monospace;">
else <span style="color: #3d85c6;">//si no...</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
{ </div>
<div style="font-family: "Courier New",Courier,monospace;">
printf("El mayor es %d \n",num2); <span style="color: #3d85c6;">//Escribimos que el mayor es num2.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
}</div>
<div style="font-family: "Courier New",Courier,monospace;">
system("PAUSE"); <span style="color: #3d85c6;">//Hacemos un pause en el programa para que de tiempo a ver el resultado.</span></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
}</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<br />Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com2tag:blogger.com,1999:blog-1511459546315590868.post-71775979833537258652012-03-25T03:11:00.001-07:002012-03-26T11:35:23.306-07:00Comandos Linux (Los más usados).<div style="color: black; font-family: "Courier New",Courier,monospace;">
Una lista con los comandos más usados en la terminal de Linux.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Archivos y Directorios:</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd /home</b>: entrar en el directorio home.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd ..</b>: retroceder un nivel.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd ../..</b>: retroceder dos niveles.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd: </b>ir al directorio raiz.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd ~user1</b>: ir al directorio user1.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cd -</b>: regresar al directorio anterior.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- pwd</b>: mostrar el camino del directorio de trabajo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ls</b>: listar los ficheros de un directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ls -F</b>: ver los ficheros de un directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ls -l</b>: mostrar los detalles de ficheros y carpetas de un directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ls -a</b>: mostrar los ficheros ocultos.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- tree</b>: mostrar los ficheros y carpetas en forma de árbol comenzando por la raíz.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- lstree</b>: mostrar los ficheros y carpetas en forma de árbol comenzando por la raíz.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- mkdir carp1</b>: crear una carpeta o directorio con nombre carp1.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- mkdir carp1 carp2</b>: crea dos carpetas o directorios simultáneamente.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- mkdir -p /carp0/carp1/carp2</b>: crea un árbol de directorios.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- rm archivo1</b>: borra el archivo llamado archivo1.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- rm -f archivo1</b>: borra el archivo llamado archivo1.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- rmdir dir1</b>: borra la carpeta llamada dir1.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- rm -rf dir1</b>: borra la carpeta llamada dir1 y todo su contenido. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- rm -rf dir1 dir2</b>: borra dos carpetas con todo su contenido.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- mv dir1 nuevo_dir</b>: cambia el nombre de dir1 a nuevo_dir.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- mv /dir1/file /dir2 </b>mueve el archivo file de la carpeta dir1 a la carpeta dir2.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp archivo.txt</b>: copia un archivo llamado archivo.txt</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp archivo1 archivo2</b>: copia dos archivos a la vez.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp dir /*</b>: copia todos los ficheros de un directorio dentro del directorio de trabajo actual.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp -a /tmp/dir1</b>: copa un directorio dentro del directorio de trabajo actual.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp -a dir1</b>: copiar un directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- cp -a dir1 dir2</b>: copia dos directorios a la vez.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ln -s file1 lnk1</b>: crea un enlace simbólico al fichero o directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- ln file1 lnk1</b>: crea un enlace físico al fichero o directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- touch -t 0854450000 file1</b>: modifica el tiempo de creación de un fichero o directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>- file file1</b>: salida (volcado en pantalla) del tipo mime de un fichero de texto.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black;">
<span style="font-family: "Courier New",Courier,monospace;">Continuará...</span></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-11488128213486973082012-03-15T12:21:00.000-07:002012-03-26T11:34:09.349-07:00Montar particiones de forma autómatica en Linux<div style="color: black; font-family: "Courier New",Courier,monospace;">
Muchas veces tenemos en nuestro sistema particiones que nos piden poner contraseña para montarlas cada vez que iniciamos sesión.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
A priori no es un drama, pero se reconoce que es un poco molesto el andar metiendo la contraseña cada vez que quieres acceder a un dato de esa partición.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La forma de solucionar esto es configurar la partición para que se automonte al arranque del sistema, y ya esté accesible desde el primer momento sin necesidad de poner contraseña.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El archivo a modificar se encuentra en /etc/fstab.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pero existe una aplicación que nos lo pone mucho más facil a la hora de configurar el automontaje de nuestras particiones.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Se trata de PySDM.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Este programa se encuentra en la mayoría de repositorios oficiales de nuestra distro. Basta con ir a la terminal a descargarla:</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
<b><i style="color: #666666;">apt-get install pysdm</i></b> <span style="color: black;">(si estás con una distro basada en Debian)</span></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
o </div>
<div style="font-family: "Courier New",Courier,monospace;">
<b style="color: #666666;"><i>yum install pysdm</i></b> <span style="color: black;">(si estás con una distro basada en Red Hat)</span></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Antes de tocar nada, conviene hacer una copia de seguridad del archivo fstab.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Desde la terminal y como root, nos situamos en la carpeta /etc y tecleamos:</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>cp fstab fstab-old</i></b></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Con esto hacemos una copia de fstab en un archivo llamado fstab-old.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si la fastidiamos en algún momento, podemos restaurar el fstab tecleando:</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>cp fstab-old fstab </i></b></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para iniciarlo lo tecleamos desde la terminal</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>pysdm</i></b></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifRkaajScFuUmVMtwVHUlolwysKz18O9gWn5YF3w7dMRsfeUKlDxN99JCNOnp1pcoctG6dYLxCr6oXoJtOoQgvN1fefAeGFG60goCUDNYKQ_K4qdZMeOf8ZS4UGKRv5BgBltzFE2dOA1I/s1600/pys01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifRkaajScFuUmVMtwVHUlolwysKz18O9gWn5YF3w7dMRsfeUKlDxN99JCNOnp1pcoctG6dYLxCr6oXoJtOoQgvN1fefAeGFG60goCUDNYKQ_K4qdZMeOf8ZS4UGKRv5BgBltzFE2dOA1I/s1600/pys01.jpg" /></a></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Como vemos en la imagen, a la derecha se nos muestra nuesto disco duro sda, y dentro las particiones disponibles, sda1, sda2, y sda3.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En mi caso, la primera partición, sda1 es la partición del sistema, la sda2 es la partición swap, y la sda3 es una partición NTFS que necesitaba autenticar por contraseña cada vez que iniciaba sesión en el equipo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Así que marcamos la partición a automontar, y clicamos en Asistente.</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXWXPQh5pUUMqsCbIPZJrM7ztGn5Nfrj-VBDfJweMAqkbhINnYzzxyUHBRQk9r8_hrgOXSTFt-SlRPZMsZwiPlef1TW7u7vcg6_xWHYjWGlzS_sYa6fFtsuQQnc4e43EJh7XKGzMrrfi8/s1600/pys02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXWXPQh5pUUMqsCbIPZJrM7ztGn5Nfrj-VBDfJweMAqkbhINnYzzxyUHBRQk9r8_hrgOXSTFt-SlRPZMsZwiPlef1TW7u7vcg6_xWHYjWGlzS_sYa6fFtsuQQnc4e43EJh7XKGzMrrfi8/s1600/pys02.jpg" /></a></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Aquí nos aseguramos de que esté marca la opción:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<i>"Montar el sistema de ficheros en el arranque"</i>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Y que esté NO esté marcada la opción:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<i>"Sistema de solo lectura"</i>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Aceptamos, y luego Aplicamos.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Tras reiniciar, ya se nos montará esa partición automáticamente.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black;">
<br /></div>
<br />
<br />Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com1tag:blogger.com,1999:blog-1511459546315590868.post-37288970611257510102012-03-13T15:11:00.000-07:002012-03-26T11:37:23.223-07:00Instalar Prestashop en Linux<div style="color: black; font-family: "Courier New",Courier,monospace;">
En esta guía vamos a explicar cómo instalar el gestor de tiendas virtuales de código abierto, Prestashop, en nuestra máquina Linux.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La instalación no difiere mucho respecto a la de Windows, aunque existen un par de detalles que mencionaremos posteriormente.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Antes de instalar Prestashop y ejecutarlo en modo local, necesitamos que se encuentren instalados: Apache, PHP y mySQL.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para instalar estos módulos puedes consular <b><a href="http://programador-apli.blogspot.com/2012/02/instalar-php-en-nuestra-maquina.html">esta entrada</a></b> donde se explicó cómo instalar el paquete XAMPP en Linux. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Empezamos...</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo primero será acudir a la <b><a href="http://www.prestashop.com/">web</a></b> del proyecto y descargar el paquete Prestashop, que está comprimido en zip.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos extraerla con nuestro descompresor favorito, o podemos acceder a una terminal, situarnos en el directorio donde se ha descargado y teclear:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>unzip prestashop_1.4.7.0.zip</i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVhexsTyTE02lPkVfzjHckb-zLk4MwYHjLoed8vLmsxgS8ABYVLOIGb54UiwDyeUN7I3Z9Xy-l_btO_zH0_WTE0Muk23EiidZDhyMKZfZm8jtATEVJhFLSQC1J7s6TyrWJ4GaEDkHQ_8Y/s1600/Presta01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVhexsTyTE02lPkVfzjHckb-zLk4MwYHjLoed8vLmsxgS8ABYVLOIGb54UiwDyeUN7I3Z9Xy-l_btO_zH0_WTE0Muk23EiidZDhyMKZfZm8jtATEVJhFLSQC1J7s6TyrWJ4GaEDkHQ_8Y/s1600/Presta01.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Una vez descomprimido, vemos que la carpeta que nos ha generado:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc_C1y3P9Y2wcUPRgIZxS9o4wX_VvDHfvHIlQl6sLXCukRvs56RGSfw470E2QcijZs9HTU06Ium_gmZ8prTaWbwCD1zn1f3vi9AY1o916N5qoxxEBde6Hk3ZuckBTxWmyuviT9-MQWaCY/s1600/Presta02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc_C1y3P9Y2wcUPRgIZxS9o4wX_VvDHfvHIlQl6sLXCukRvs56RGSfw470E2QcijZs9HTU06Ium_gmZ8prTaWbwCD1zn1f3vi9AY1o916N5qoxxEBde6Hk3ZuckBTxWmyuviT9-MQWaCY/s1600/Presta02.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Bien, esta carpeta tenemos que copiarla dentro de /opt/lampp/htdocs.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pero si intentamos copiarla tal cual, nos va a decir que no tenemos permisos para realizar la acción.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Así que vamos a copiarla utilizando la terminal.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo primero nos identificamos como root:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>su</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>password</i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Nos situamos en el directorio donde se encuentra la carpeta Prestashop, y tecleamos:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>cp -R prestashop /opt/lampp/htdocs</i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv7Tf79fDLBltoNVmU3F17g1mC8ytBdnQChyphenhyphenFWUnacXLjsxWQ3WbSyiKN3Oy478Qv5CqaoCbS9Q9WN0m0SL_X5NCKd93gavRp63UJO_qUrcc-Eb7nFjtltUoqcE_rSU9Q-xOu8nf_aJ54/s1600/Presta03.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv7Tf79fDLBltoNVmU3F17g1mC8ytBdnQChyphenhyphenFWUnacXLjsxWQ3WbSyiKN3Oy478Qv5CqaoCbS9Q9WN0m0SL_X5NCKd93gavRp63UJO_qUrcc-Eb7nFjtltUoqcE_rSU9Q-xOu8nf_aJ54/s1600/Presta03.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Con<i> cp</i> copiamos, con <i>-R</i> le decimos que incluya todos los archivos y subdirectorios que hay en el interior, y lo último es la ruta en donde queremos copiarlo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Nos aseguramos de que se ha copiado correctamente:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioD7UKypOIV6QUJUAz7jbxkCoaqhOUckUskHyV8SMOMayxo9_Ihi3DhIhZs7e6bYE1y_Lk9y3bb_IFi0OIjQ6ZbFG5kxri1URJqmUPW4x818csFczz35zAcKoHfPtZw805cXGcRK8z4Zw/s1600/Presta04.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioD7UKypOIV6QUJUAz7jbxkCoaqhOUckUskHyV8SMOMayxo9_Ihi3DhIhZs7e6bYE1y_Lk9y3bb_IFi0OIjQ6ZbFG5kxri1URJqmUPW4x818csFczz35zAcKoHfPtZw805cXGcRK8z4Zw/s1600/Presta04.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Otro paso importante:</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para instalar Prestashop, éste necesita poder leer/escribir en los archivos/carpetas de Prestashop. Pero recordemos que la carpeta /opt y todos los subdirectorios que le cuelgan solo son escribibles por root. Para cualquier otro usuario solo son de lectura.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Así que necesitamos asignar permisos de lectura/escritura a toda la carpeta prestashop, para que cualquier usuario (el propio Prestashop) tenga acceso a lectura/escritura.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El comando es:</div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><br /></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>chmod -R 0777 /opt/lampp/htdocs/prestashop</i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQUHCoqtsNjRBa1CX7t5oksMK0CwOk01aFRqd877FGFxkiPG_cCwJP2sEH1xmaAHP9n_4fBCrNQIdw2c70Hz3rZ9EuoHbfe2IwV5RQAjqnRxt6fVpcaXGhjCy78ryMTSYdi2_FLYl-qAQ/s1600/Presta05.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQUHCoqtsNjRBa1CX7t5oksMK0CwOk01aFRqd877FGFxkiPG_cCwJP2sEH1xmaAHP9n_4fBCrNQIdw2c70Hz3rZ9EuoHbfe2IwV5RQAjqnRxt6fVpcaXGhjCy78ryMTSYdi2_FLYl-qAQ/s1600/Presta05.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
chmod es el encargado de asignar permisos.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
-R le indica que afecte a todos los archivos y subdirectorios que contiene.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Los permisos en Linux se establecen mediante un número octal (con base 8), esto significa, números que comprenden entre el 0 y el 7. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El parámetro 0777 asigna permisos a cualquier usuario para lectura/escritura.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Una vez establecidos los permisos, vamos a crear la base de datos sobre la que trabajará Prestashop.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para ello accedemos al navegador y entramos en http://localhost/phpmyadmin</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT3osY68oFNji4ENZOoqhRmZUs01XC1rPlX0fACwBzkimZVEwdwfREWer5zLpr_di-raEJMUIpc7fZ7jRMmWUlTmc2iamsf2IRwx6D-T9dPfV_hq5-VzJXjJWbUH-Dpkr30089Ig7_QSY/s1600/Presta06.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT3osY68oFNji4ENZOoqhRmZUs01XC1rPlX0fACwBzkimZVEwdwfREWer5zLpr_di-raEJMUIpc7fZ7jRMmWUlTmc2iamsf2IRwx6D-T9dPfV_hq5-VzJXjJWbUH-Dpkr30089Ig7_QSY/s1600/Presta06.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pinchamos en Bases de Datos y escribimos el nombre para esta. Por ejemplo, Prestashop, y clic en Crear.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Ahora para instalar Prestashop entramos en http://localhost/prestashop:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo primero que nos aparece es el Contrato de Licencia. Siguiente:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNoJzKC6QwpBKTYMO3A4wXs9NogIm5jmZBInXDkvJbH1oTPg7fJBudXuHoZXgOLEYy9LAtpjdn5mWs4DNM-NUP-tx5u6O-UJqzXVZfdhihaZl9gT6CysHr6omJsXngQ0cDwjenaIGvYfs/s1600/Presta08.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNoJzKC6QwpBKTYMO3A4wXs9NogIm5jmZBInXDkvJbH1oTPg7fJBudXuHoZXgOLEYy9LAtpjdn5mWs4DNM-NUP-tx5u6O-UJqzXVZfdhihaZl9gT6CysHr6omJsXngQ0cDwjenaIGvYfs/s1600/Presta08.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
A continuación nos pide un nombre para el servidor, el nombre de la base de datos que habíamos creado, el usuario de la base de datos, etc..</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos dejar las opciones por defecto:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjIpe4-26a08BJX3CW53bojCh1vcwkNdKm5oIShT37jeMYtgrCpR_ruslHrNRKDncInyifoKWm9GG8vWpRufTjlmhOFtCCr6pvQJKjr1T70h_qBr7xu-ODiS0WLdEjmbNH0HjMAG1Ui4M/s1600/Presta09.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjIpe4-26a08BJX3CW53bojCh1vcwkNdKm5oIShT37jeMYtgrCpR_ruslHrNRKDncInyifoKWm9GG8vWpRufTjlmhOFtCCr6pvQJKjr1T70h_qBr7xu-ODiS0WLdEjmbNH0HjMAG1Ui4M/s1600/Presta09.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En tipo de instalación podemos darle a Modo Completo, para que nos incluya todos los módulos y la tienda de ejemplo para ver cómo funciona y poder modificarla a nuestro antojo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El e-mail es opcional y como bien dice, configurarlo es para expertos únicamente, jeje.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmJmnWKY_NFih8CweCoATK57YKycGGeoM63zTDwHvmCrc2TqYDCzPawg91-daOLuif7ccAwskQlEDh-r_KSxff8ld2j4cfUdvajhqa3WVs_XdMPF3eOT8rwgqu_047C5WkVHmqAeV3RAg/s1600/Presta10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmJmnWKY_NFih8CweCoATK57YKycGGeoM63zTDwHvmCrc2TqYDCzPawg91-daOLuif7ccAwskQlEDh-r_KSxff8ld2j4cfUdvajhqa3WVs_XdMPF3eOT8rwgqu_047C5WkVHmqAeV3RAg/s1600/Presta10.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Más datos sobre nuestra tienda. Podemos poner el nombre, el tipo de actividad que vamos a realizar, escoger un logo, etc.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo2VQyQ890A7GwvtMP_AHvKPVv1KU-lamuqV3gdkUOQTSC99VUJiKeXGv6evbAIk5q9oFXgXNqbXezJcL9D1UBKh4Hqzg_EUWHHmiWlyisYozlo6HMa5mcGg9gNY0wTJzyzQ7exNbS6h4/s1600/Presta11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo2VQyQ890A7GwvtMP_AHvKPVv1KU-lamuqV3gdkUOQTSC99VUJiKeXGv6evbAIk5q9oFXgXNqbXezJcL9D1UBKh4Hqzg_EUWHHmiWlyisYozlo6HMa5mcGg9gNY0wTJzyzQ7exNbS6h4/s1600/Presta11.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Escribimos nuestro nombre y apellido.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Muy importante la dirección de email que pongamos aquí y la contraseña, pues es la que nos va a pedir cuando administremos la tienda.</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzVHLidapNWfNRA0rYaU0gvJIOMP4_HwSU3HMoLZcLg7JPqrhd2TDKvZgtsPuQHEtzMRqIZmEs9ycKbqIhJA8_swQ2hLcpEEvl7xVCVJQ7xxVQwWIdKSHI0W7YOaHg9jFGAbjNoUONp2o/s1600/Presta12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzVHLidapNWfNRA0rYaU0gvJIOMP4_HwSU3HMoLZcLg7JPqrhd2TDKvZgtsPuQHEtzMRqIZmEs9ycKbqIhJA8_swQ2hLcpEEvl7xVCVJQ7xxVQwWIdKSHI0W7YOaHg9jFGAbjNoUONp2o/s1600/Presta12.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La hemos terminado la instalación. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQcnOBBHQa2nOaQDzQ87XMEqYMQFaxQ9z0_NPS5Zy0wpcEjTfjcHg0hMKZQmUTrMbToPVizRIaRCia9O26Ttx4rtil0wzZeCnq2aTZkN-WT-oekuLckP7e57QR5BZ65M3JIb-znLfK_J0/s1600/Presta13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQcnOBBHQa2nOaQDzQ87XMEqYMQFaxQ9z0_NPS5Zy0wpcEjTfjcHg0hMKZQmUTrMbToPVizRIaRCia9O26Ttx4rtil0wzZeCnq2aTZkN-WT-oekuLckP7e57QR5BZ65M3JIb-znLfK_J0/s1600/Presta13.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Como vemos en el mensaje, nos dice que para más seguridad borremos la carpeta <i>install</i> que se encuentra dentro de la carpeta Prestashop.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pues nos vamos a la terminal, nos siguamos en el directorio de prestashop:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>cd /opt/lampp/htdocs/prestashop</i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
y tecleamos:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>rm -rf install </i>(siempre identificado como root)</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP-t4yuwSXaolg3uoAucORcqBAWdGJzJvWTJ-FTxNq4jEgjOEEy15tc5vvqN8IHg5NxBN8cR2p_En90t2KFDbf0zvKlHRBGh4AQ0augw4ePocfHje7CqvYUUAwsfQYRRWkFgkE2kwi0KM/s1600/Presta15.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP-t4yuwSXaolg3uoAucORcqBAWdGJzJvWTJ-FTxNq4jEgjOEEy15tc5vvqN8IHg5NxBN8cR2p_En90t2KFDbf0zvKlHRBGh4AQ0augw4ePocfHje7CqvYUUAwsfQYRRWkFgkE2kwi0KM/s1600/Presta15.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
rm borra el directorio</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
-rf borra todos los archivos y subdirectorios internos y además no nos pregunta uno a uno si estamos seguros de borrarlos, ya que son bastantes archivos y directorios, y podemos estar un buen rato confirmando el borrado de cada archivo/directorio.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
También tenemos que renombrar el directorio /admin.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pues ya que tenemos la terminal abierta la renombramos, por ejemplo, a admin1:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>mv admin admin1</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2Ga8c64Y6b4QCQoHkX4YwLEeNtEytW5oGZgSRftSHJk9woXTtCOs6C-6HYA-LmqR0IhQ_DP6czN-CWQBuRSSsueT51KUufA0B4L3mCB7yAVA6cNxeA2c7SIGmSEVYjzDpFqh8X_GzLM/s1600/Presta16.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ2Ga8c64Y6b4QCQoHkX4YwLEeNtEytW5oGZgSRftSHJk9woXTtCOs6C-6HYA-LmqR0IhQ_DP6czN-CWQBuRSSsueT51KUufA0B4L3mCB7yAVA6cNxeA2c7SIGmSEVYjzDpFqh8X_GzLM/s1600/Presta16.jpg" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Y para acceder a nuestra tienda entramos en http://localhost/prestashop</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="color: black; font-family: "Courier New",Courier,monospace; margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGwt9bmLCjyQjTSO4VpvqewU_5kcZ2rpeYhASd6c9MRwO5NNQ1cXDE8_x39mpqomlKoSWG1cE1TTzUcsyyTtQTvJCSZuENJk0XP-zboyl2cNveqjPS_sJirnm8HDOdrFTXGN9MfE83MS4/s1600/Presta17.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="331" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGwt9bmLCjyQjTSO4VpvqewU_5kcZ2rpeYhASd6c9MRwO5NNQ1cXDE8_x39mpqomlKoSWG1cE1TTzUcsyyTtQTvJCSZuENJk0XP-zboyl2cNveqjPS_sJirnm8HDOdrFTXGN9MfE83MS4/s640/Presta17.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Añadir leyenda</td></tr>
</tbody></table>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br />
Para acceder a la zona de administración, entramos en http://localhost/prestashop/admin1</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz3vgIWbWke4mZ0rLjFhHiQjPAimrTpir1I17eWmJbkriW_c6q6XRAC31mpWfEh1b5aK3t4E9jSEAmVok3Hh0ZF9AaI7KrT1iwbBwbh-KziNUfcssXVy1SLa_F-RKQEdpqvtdUKes1stU/s1600/Presta19.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="331" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz3vgIWbWke4mZ0rLjFhHiQjPAimrTpir1I17eWmJbkriW_c6q6XRAC31mpWfEh1b5aK3t4E9jSEAmVok3Hh0ZF9AaI7KrT1iwbBwbh-KziNUfcssXVy1SLa_F-RKQEdpqvtdUKes1stU/s640/Presta19.jpg" width="640" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Y eso es todo.</div>
<div style="font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com4tag:blogger.com,1999:blog-1511459546315590868.post-86350713000296714472012-03-01T12:22:00.001-08:002012-03-26T11:40:54.887-07:00Arrays (Tablas) Parte 2<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC3-zEGh9dyTJq5DVQGYgiwtPJiO6UW09zAS0s7rG3eEwPHW8OYg7e-yXVgoS2lrBmF_X4nFQyqN0lE00nenof9VoQcPNhMnO1_YOp4jxMbgUf40wwOD7z4DHrdCSAvNMP1SN-ssFfDM0/s1600/logo_arrays_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC3-zEGh9dyTJq5DVQGYgiwtPJiO6UW09zAS0s7rG3eEwPHW8OYg7e-yXVgoS2lrBmF_X4nFQyqN0lE00nenof9VoQcPNhMnO1_YOp4jxMbgUf40wwOD7z4DHrdCSAvNMP1SN-ssFfDM0/s1600/logo_arrays_2.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
<b>Arrays Multidimensionales</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Los arrays multidimensionales son arrays en los cuales cada elemento es otro array.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><?php</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[0] = array (1, "enero", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[1] = array (2, "febrero", 28);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[2] = array (3, "marzo", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[3] = array (4, "abril", 30);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[4] = array (5, "mayo", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[5] = array (6, "junio", 30);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[6] = array (7, "julio", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[7] = array (8, "agosto", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[8] = array (9, "septiembre", 30);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[9] = array (10, "octubre", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[10] = array (11, "noviembre", 30);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$calendario[11] = array (12, "diciembre", 31);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>reset ($calendario);</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>while (list ($clave, $valor) = each ($calendario)) {</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$cadena = $valor[1];</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$cadena .= " es el mes número " . $valor[0];</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>$cadena .= " y tiene " . $valor[2] . " días <BR>";</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>echo $cadena;</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>}</i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i><br /></i></b></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<b><i>?> </i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Vamos a explicar este ejemplo de array multidimensional.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
1º Hemos declarado un array llamado $calendario. Este calendario está formado por 12 elementos que serían los 12 meses del año.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
2º A cada elemento hemos declarado un array que recoge tres valores, el número de mes, el nombre del mes y el número de días que tiene ese mes.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por lo que hemos metido un arrays dentro de otro array que era lo que se pretendía.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
3º Hemos creado un bucle <i>While</i> para recorrer los arrays. Con la función <i>list</i> hemos declarado las variables $clave y $valor para ir recogiendo los valores del array, y con la función <i>each</i>, extraemos el valor del elemento actual y pasamos al siguiente.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
4º Hemos creado una variable llamada $cadena para que almacene los elementos de los arrays internos. Recordamos que cada array interno tenía 3 valores:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
valor[0] = Número del mes.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
valor[1] = Nombre del mes.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
valor[2] = Número de días que tiene el mes.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
5º Por último hemos creado un <i>echo</i> para $cadena y nos ha imprimido lo que le hemos indicado:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
enero es el mes número 1 y tiene 31 días <br />
febrero es el mes número 2 y tiene 28 días <br />
marzo es el mes número 3 y tiene 31 días <br />
abril es el mes número 4 y tiene 30 días <br />
mayo es el mes número 5 y tiene 31 días <br />
junio es el mes número 6 y tiene 30 días <br />
julio es el mes número 7 y tiene 31 días <br />
agosto es el mes número 8 y tiene 31 días <br />
septiembre es el mes número 9 y tiene 30 días <br />
octubre es el mes número 10 y tiene 31 días <br />
noviembre es el mes número 11 y tiene 30 días <br />
diciembre es el mes número 12 y tiene 31 días<br />
<br />
<div>
Veamos otro ejemplo.</div>
<div>
<br /></div>
<div>
Imaginemos que tenemos una lista de empleados y queremos almacenar en un array sus nombres, edad y estado civil.</div>
<div>
<br /></div>
<div style="color: #666666;">
<i><b><?php</b></i></div>
<div style="color: #666666;">
<i><b>$empleados[0] = array ("Pedro", 34, "casado");</b></i></div>
<div style="color: #666666;">
<i><b>$empleados[1] = array ("Jorge", 26, "soltero");</b></i></div>
<div style="color: #666666;">
<i><b>$empleados[2] = array ("Ana", 28, "casada");</b></i></div>
<div style="color: #666666;">
<i><b>$empleados[3] = array ("Julia", 30, "soltera");</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>reset ($empleados);</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>while (list ($clave, $valor) = each ($empleados)) {</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>$cadena = $valor[0];</b></i></div>
<div style="color: #666666;">
<i><b>$cadena .= " tiene " . $valor[1] . "años";</b></i></div>
<div style="color: #666666;">
<i><b>$cadena .= " y está " . $valor[2];</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>echo $cadena;</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>}</b></i></div>
<div style="color: #666666;">
<i><b><br /></b></i></div>
<div style="color: #666666;">
<i><b>?></b></i></div>
<div>
<br /></div>
<div>
Imprimiría:</div>
<div>
<br /></div>
<div>
Pedro tiene 34 años y está casado</div>
<div>
Jorge tiene 26 años y está soltero</div>
<div>
Ana tiene 28 años y está casada</div>
<div>
Julia tiene 30 años y está soltera</div>
<div>
<br /></div>
<div>
</div>
</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En el próximo capítulo hablaremos de Bucles y Repeticiones.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-65803769085153874022012-03-01T09:37:00.000-08:002012-03-26T11:42:42.816-07:00Arrays (Tablas) Parte 1<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjX_B7tHlhVV2EhnDGIzmPChs4P14zWENPBcw9Y06hfDaWj89LkjDf1abOACiwYAC0ENNdpqybxKG1C1nsip8TqkWFUsc2gbhSbUFGG3K-gK5j9T_CAcaG66tfIByFKI191rFG8Lpp3V8M/s1600/logo_arrays_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjX_B7tHlhVV2EhnDGIzmPChs4P14zWENPBcw9Y06hfDaWj89LkjDf1abOACiwYAC0ENNdpqybxKG1C1nsip8TqkWFUsc2gbhSbUFGG3K-gK5j9T_CAcaG66tfIByFKI191rFG8Lpp3V8M/s1600/logo_arrays_1.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
Los arrays son variables que permiten almacenar varios elementos, estructurándolos como si fuesen una tabla, de ahí a que también se les llamen tablas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Imaginemos que tenemos una variable llamada $pais, y que a esa variable queremos incluirle varios nombres de países.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo declararíamos de la siguiente forma:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais[0] = "España";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais[1] = "Francia";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais[2] = "Portugal";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais[3] = "Alemania";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais[4] = "Polonia";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Yo vivo en " .$pais[0]; </b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto imprimiría "Yo vivo en España".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Al número entre corchetes [] se le llama índice. Si cambiamos el índice en el echo, nos imprimirá el elemento de ese índice.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Se puede declarar el array de forma más rápida, de la siguiente forma:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais = array("España", "Francia", "Portugal", "Alemania", "Polonia");</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Yo vivo en " .$pais[0];</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?> </b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Nos imprimiría el mismo resultado. Solo hay que contar los índices, teniendo en cuenta que el primer índice será el 0.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si queremos que el índice empiece por otro número, deberemos declararlo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais = array(1=> "España", "Francia", "Portugal", "Alemania", "Polonia");</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br />
A los elementos de array se les pueden asignan otros valores llamados claves (<i>keys</i>). A estos arrays se les llama Tablas Asociativas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Imaginemos que dentro del array países, que contiene varios elementos (países), queremos además asociar el idioma que se habla en cada uno de ellos.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos hacerlo de las dos formas al igual que antes:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais["Espana"] = "Español";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais["Francia"] = "Frances";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais["Portugal"] = "Portugues";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais["Alemania"] = "Aleman";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais["Polonia"] = "Polaco";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El problema ahora sería recorrer la tabla para sacar el valor que nos interesa, ya que antes lo teniamos fácil al apuntar a su índice. Pero ahora el índice a cambiado al nombre del elemento.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Necesitamos recurrir a un bucle para que recorra el array. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por defecto, el puntero interno se sitúa sobre el primer elemento de la tabla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Haremos uso de las siguientes funciones:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>current</i> para devolver el valor del elemento donde se encuentra el puntero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>reset</i> para mover el puntero al primer elemento de la tabla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>end</i> para mover el puntero al último elemento de la tabla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>next</i> para mover el puntero al siguiente elemento de la tabla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>prev</i> para mover el puntero al elemento anterior de la table.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- <i>count</i> para que nos diga el número de elementos de la tabla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para recorrer la tabla utilizaremos la función <i>each().</i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Volvemos al ejemplo anterior de los países:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$pais = array ("Espana"=>"Español", "Francia"=>"Frances", "Portugal"=>"Portugues", "Alemania"=>"Aleman", "Polonia"=>"Polaco");</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>reset($pais); //situamos el puntero en el primer elemento.</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>while (list($clave, $valor) = each($pais)) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "En el pais " . $clave . " se habla " . $valor . "<BR>";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto imprimirá:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En el pais Espana se habla Español<br />
En el pais Francia se habla Frances<br />
En el pais Portugal se habla Portugues<br />
En el pais Alemania se habla Aleman<br />
En el pais Polonia se habla Polaco</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Repasemos el código:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Declaramos el array $pais, con una lista de elementos (países) con unos valores asociados (idiomas).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Colocamos el puntero en el primer elemento de la tabla con <i>reset</i>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Creamos un bucle <i>While</i> en el que listamos (<i>list</i>) las claves (paises) y valores (idiomas) de cada elemento de la tabla, y con <i>each</i> extraemos el valor del elemento actual y pasamos al siguiente, hasta que llega al final.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En la 2ª parte veremos los <a href="http://programador-apli.blogspot.com/2012/03/arrays-tablas-parte-2.html">Arrays Multidimensionales</a>. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-70541275977459543012012-02-29T11:23:00.001-08:002012-03-26T11:43:26.833-07:00Un poco de síntaxis<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVr1swpNneAWuYFWipTlwKhPEJhvIzHRYv9Xqwr1z0-QtyVyvWdsv1N8sIk8tH5lyWMSBFLE1X02GklaCMjQbfgEYq2f1jZ_nraAeeL3duiX367uV3g5RbOL1V24WyqsX9u36uPeRciis/s1600/logo_sintaxis.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVr1swpNneAWuYFWipTlwKhPEJhvIzHRYv9Xqwr1z0-QtyVyvWdsv1N8sIk8tH5lyWMSBFLE1X02GklaCMjQbfgEYq2f1jZ_nraAeeL3duiX367uV3g5RbOL1V24WyqsX9u36uPeRciis/s1600/logo_sintaxis.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
Todo código PHP debe ir dentro de las etiquetas <?php y ?>.<br />
También es aceptado <? y ?>, ya depende de gustos. <br />
<br />
En PHP las variables son declaradas mediante el símbolo del dólar ($) y les asignamos un valor por medio del signo igual (=), por eso en PHP el (=) no significa igual, sino asignación.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$nombre = "Javier"; //Asignamos a la variable $nombre el valor "Javier".</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Recordemos que PHP es sensible a mayúsculas y minúsculas, por lo que no es lo mismo $variable que $Variable. Ambas son consideradas variables distintas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Comentarios:</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En PHP es posible realizar comentarios dentro del código, muy útil para explicar partes de código que con el tiempo podemos olvidar para qué las hicimos.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Existen varias formas de realizar comentarios:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>// para realizar un comentario de una sola línea.</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><br /></b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>/* */ Para realizar comentarios en varias líneas.</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><br /></b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>//esto es un comentario</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><br /></b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>/* esto también</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>es un </b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>comentario */</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><br /></b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Todo lo que escribamos entre estas etiquetas no será interpretado como código PHP.<br />
<br />
Otras opciones útiles para implementar dentro de PHP son: </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<i style="color: #666666;"><b>\n</b></i> (Nueva línea), sirve para indicarle a PHP que queremos realizar un salto de línea.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<i style="color: #666666;"><b>\t</b></i> (tabulador horizontal).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<i style="color: #666666;"><b>\r</b></i> (retorno del carro).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En el próximo capítulo comenzaremos por las <a href="http://programador-apli.blogspot.com/2012/02/variables.html">Variables y Constantes</a>. </div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-77338850933323443382012-02-28T13:11:00.004-08:002012-03-26T11:44:27.313-07:00Estructuras Condicionales<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGhamSLzQZQN1SMOdrM-kVHA9lH-Jj5pLA_XRTodUIkbfWpYKWoXuakZN-Sh2EsYM3fyCm5wVT9ANqyfC39DY2mdHzgEi94Yb-cEEhyXZHgurUVy4-ThkVAlIbm1N4UpVbT_T8hEzxnRY/s1600/logo_estructuras.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGhamSLzQZQN1SMOdrM-kVHA9lH-Jj5pLA_XRTodUIkbfWpYKWoXuakZN-Sh2EsYM3fyCm5wVT9ANqyfC39DY2mdHzgEi94Yb-cEEhyXZHgurUVy4-ThkVAlIbm1N4UpVbT_T8hEzxnRY/s1600/logo_estructuras.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
Las estructuras condicionales se utilizan para tomar decisiones según se cumpla o no una determinada condición. Ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 7;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($num > 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "El número es mayor que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En este pequeño script, hemos definido una variable llamada $num, y le hemos asignado el valor de 7.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La condición es que si la variable $num es mayor que 5, muestre en pantalla el texto "El número es mayor que 5". En este caso la condición se cumple.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si el valor de $num hubiera sido inferior a 5, simplemente no se habría mostrado nada en pantalla, ya que la condición no se cumple.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La declaración de sentencias de control es sencilla:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if (condición) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>sentencia;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Todo lo que se escribe entre las llaves {} se ejecuta en caso de que la condición se cumpla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
IMPORTANTE! </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El signo "=" en PHP significa "asignación", no "igualdad".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Es decir, en una condición, sería incorrecto escribir esto:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($num = 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "El número es igual a 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo correcto es:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($num == 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "El número es igual a 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto quiere decir que para que PHP interprete el signo (=) como de igualdad, se debe representar doble (==), sino lo interpretará como asignación.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Condicionales lógicos.</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos poner más de una condición dentro de un mismo <i>if</i>, mediante un operador lógico, el &&. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$edad = 32;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($edad > 20 && $edad < 40) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Su edad es mayor de 20, pero menos de 40";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esta sentencia se traduciría coloquialmente como, "<i>Si edad es mayor que 20 y y también es menor que 40, entonces muestra en pantalla el mensaje</i>".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Hemos asignado dos condiciones, una que la edad sea mayor de 20, y otra que la edad sea menor de 40. Si se cumplen las dos condiciones, entonces muestra en pantalla el texto del <i>echo</i>, de no cumplirse alguna o ninguna de las condiciones, no se mostraría nada en pantalla. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos usar otro operador lógico, como el "||", que significa "O" y se aplica de la siguiente forma:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$edad = 10;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($edad > 20 || $edad < 40){</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "La edad es mayor de 20 o menor de 40";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esta sentencia se traduciría coloquialmente como, <i>"Si edad es mayor que 20 o es menor que 40, entonces muestra en pantalla el mensaje</i>".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En este caso no es necesario que las dos condiciones se cumplan, basta con que se cumpla alguna de ellas para que se ejecute la sentencia.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por último podemos usar el operador lógico de negación "!".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Este operador hace justo lo contrario de lo que englobe la condición, por ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$edad = 10;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if (! ($edad > 20)) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "La edad No es mayor de 20";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La condición se cumple, puesto que 10 no es mayor que 20. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Hasta ahora hemos visto cómo ejecutar una determinada sentencia si una o más condiciones se cumplen, pero no hemos visto qué podemos hacer cuando la condición NO se cumple.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para ello añadimos a nuestro script el complemento "<i>else</i>".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 7;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($num > 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Es mayor que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>} else {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Es menor que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?> </b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Dicho coloquialmente diríamos, <i>Si el número es mayor que 5, muéstrame "Es mayor que 5", y si no, muéstrame "Es menor que 5".</i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En este ejemplo, 7 es mayor que 5, y mostraría el primer <i>echo</i>. Si el número hubiera sido por ejemplo 3, ignoraría el primer <i>echo</i> y saltaría al segundo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<i> </i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pero puede ser que queramos definir más condiciones con distintos resultados, en lugar de los dos posibles (Sí y No). Para ello usamos "<i>else if</i>".</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Lo vemos mejor con un ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>if ($num > 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Es mayor que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>} else if ($num == 5) {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Es igual que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>} else {</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Es menor que 5";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>}</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Dicho coloquialmente sería, <i>Si el número es mayor que 5, muéstrame "Es mayor que 5", si no, si el número es igual que 5, muéstrame "Es igual que 5", si no, muéstrame "Es menor que 5".</i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Así pues, podemos poner tantas condiciones queramos con solo añadir líneas de <i>else if </i>, y para la última condición usamos el <i>else</i> a solas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Bueno, nos tomamos un descanso y seguiremos con los <a href="http://programador-apli.blogspot.com/2012/03/arrays-tablas-parte-1.html">Arrays o Tablas</a>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-72107966121899475072012-02-28T10:20:00.003-08:002012-03-26T11:45:21.193-07:00Operadores<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6iedxpkymLP4RlfG-XIcA-Pd2AkDBZ0qBLimDIADNC4qv8f0VknAxhpYc-ES_jSzOqFiIKbPoxX9PWHEYzQbCBW6w9zGYe8S5brL4EDATSeucKEN-wNP72rTulxjBYVeKDub8BKk5lOU/s1600/logo_operadores.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6iedxpkymLP4RlfG-XIcA-Pd2AkDBZ0qBLimDIADNC4qv8f0VknAxhpYc-ES_jSzOqFiIKbPoxX9PWHEYzQbCBW6w9zGYe8S5brL4EDATSeucKEN-wNP72rTulxjBYVeKDub8BKk5lOU/s1600/logo_operadores.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
<b>Operadores Básicos.</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Los operadores se utilizan para realizar cálculos entre distitnas variables.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por ejemplo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 13;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $num + 7;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto imprimiría 20.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
A la variable $num que tiene el valor 13, se le ha sumado 7.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
También podemos operar con variables:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num1 = 13;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num2 = 290;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $num1 + $num2;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Imprimiría en pantalla: 303.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Los operadores básicos son:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- Suma: +</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- Resta: -</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- Multiplicación: *</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- División: /</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- Incrementación: ++</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
- Decrementación -- </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
PHP establece prioridades entre sus operadores.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Una de las prioridades es anteponer la multiplicación a la suma y a la resta.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Por ejemplo, si tenemos el siguiente script:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num1 = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num2 = 7;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num3 = 2;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $num1 + $num2 * $num3;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Podemos pensar que primero sumará 5 + 7 y luego multiplicará por 2, sin embargo lo que hace es multiplicar 7 x 2 y luego sumarle 5. Sería: 5+(7x2).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimvHBBKCnSd_A9wWtMt5o1CYMNqgSCQI5pL5Pw7KzivmtZAfonLB9hEz6lSpiVQO_dLdCLJ2ML85zp1jTKBD6wztlyNPLhesL-x3LOVL_b-1Ckhe2A62UQn6EGemGo92eECo_KGOVDbIk/s1600/Operador1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimvHBBKCnSd_A9wWtMt5o1CYMNqgSCQI5pL5Pw7KzivmtZAfonLB9hEz6lSpiVQO_dLdCLJ2ML85zp1jTKBD6wztlyNPLhesL-x3LOVL_b-1Ckhe2A62UQn6EGemGo92eECo_KGOVDbIk/s320/Operador1.jpg" width="320" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si lo que queremos es que primero sume y después multiplique, deberíamos especificarlo así:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num1 = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num2 = 7;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num3 = 2;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo ($num1 + $num2) * $num3;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Sería (5+7)x2.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgza_diaZAncjR8KZ_o9jy_WX0dP9Bao1JieMpOGTkaiVwvWClsOm8oOLLBbSELvdKISnJ4Cu396xkdq8ubRqfnahqHyqw_Bcr9Li_wfMH4CpNLkO72LbjqY4R2nuzL8vwEresVq9ljiFQ/s1600/operador2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgza_diaZAncjR8KZ_o9jy_WX0dP9Bao1JieMpOGTkaiVwvWClsOm8oOLLBbSELvdKISnJ4Cu396xkdq8ubRqfnahqHyqw_Bcr9Li_wfMH4CpNLkO72LbjqY4R2nuzL8vwEresVq9ljiFQ/s320/operador2.jpg" width="320" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Incremento:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num++;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $num;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto imprimiría en pantalla el número 6, porque a la variable $num (que tiene el valor 5), la hemos incrementado en 1 al aplicarle el operador (++).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si queremos decrementar la variable, usamos el operador (--).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$num--;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $num;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?> </b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Imprimiría 4 en pantalla.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Operadores de comparación:</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
< menor que.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
> mayor que.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<= menor o igual que.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
>= mayor o igual que.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
== igual que. (no confundir con =, que lo que hace es asignar a una variable un valor).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
!= distinto que.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b>Operadores lógicos:</b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
AND Verdadero si ambos son verdadero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
&& Verdadero si ambos son verdadero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
OR Verdadero si alguno de los dos es verdadero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
|| Verdadero si alguno de los dos es verdadero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
XOR Verdadero si sólo uno de los es verdadero.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Todos estos operadores los veremos en próximos ejercicios.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En el próximo capítulo veremos las <a href="http://programador-apli.blogspot.com/2012/02/estructuras-condicionales.html">Estructuras condicionales</a> e implementaremos los operadores en ellas. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<b> </b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-14287100934193876602012-02-28T01:50:00.001-08:002012-03-26T11:46:03.358-07:00Variables y Constantes<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhea2hP8JamWTr_5GRXfcciOd1rqcicfVkO4aIugQnx4ymcHeUXBcudQwd5zQj0QAn74ClaWSzij_YTFCfPIXSRgJMtl1t383rfK7rY-Wtb3_0cl2EgtTsnztTRyKmj__9Ulmh4Pe8LxLo/s1600/titulo_variables.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhea2hP8JamWTr_5GRXfcciOd1rqcicfVkO4aIugQnx4ymcHeUXBcudQwd5zQj0QAn74ClaWSzij_YTFCfPIXSRgJMtl1t383rfK7rY-Wtb3_0cl2EgtTsnztTRyKmj__9Ulmh4Pe8LxLo/s1600/titulo_variables.jpg" /></a></div>
<br />
<br />
Las variables son los elementos más básicos dentro de cualquier lenguaje de programación. Se utilizan para que el ordenador memorice un determinado valor o dato que luego se usará o modificará más adelante.<br />
<br />
Antes de nada, comentamos que para iniciar cualquier programa o script en PHP, debemos definirlo entre las etiquetas <i><?php </i>y <i>?></i>. Todo el código en el interior será interpretado como código PHP por el servidor. </div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
La definición o creación de una variable en PHP se realiza de la siguiente forma:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$nombre = "Dani";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Hemos declarado una variable llamada <i>nombre </i>y le hemos dado el valor de <i>Dani</i>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Las variables en PHP se declaran anteponiendo el signo del dólar ($), y el nombre ha de empezar por una letra o una raya (_).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Si el valor de la variable es una cadena de texto, se colocará entre comillas, sin embargo, si el valor es de tipo número con el que luego vamos a operar, se declarará sin comillas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$numero = 5;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?> </b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Todas las sentencias de PHP finalizan con punto y coma (;).<br />
<br />
PHP es sensible a Mayúsculas y minúsculas, por lo que:<br />
$nombre = "Carlos"; no es igual que $nombre = "carlos";<br />
PHP lo interpretará como dos variables distintas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Vamos a poner un ejemplo muy básico de cómo podemos usar una variable:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$color = "Azul";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo $color;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Esto imprimirá en pantalla:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXR5ZHuHqWYHzUgpcz1YXl0ZLNK5C3ua-KyDyNJhp685a6H-pJ5yKwvC4hFfWQe5lDCNgmchyphenhyphenzmdHYxZW5FbH6iobvFwNHbqJJACz-ejk6eQ_SvRLsrU4tR3L7Gi6Baawzbzktx4PNfqY/s1600/variable.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="285" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXR5ZHuHqWYHzUgpcz1YXl0ZLNK5C3ua-KyDyNJhp685a6H-pJ5yKwvC4hFfWQe5lDCNgmchyphenhyphenzmdHYxZW5FbH6iobvFwNHbqJJACz-ejk6eQ_SvRLsrU4tR3L7Gi6Baawzbzktx4PNfqY/s320/variable.jpg" width="320" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El comando <i>echo</i> se utiliza para mostrar en pantalla la información que se le indique y puede ser combinado con cualquier etiqueta HTML, por ejemplo <font>, <b>, <br>, etc.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Otro ejemplo más completo:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b><?php</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$nombre = "Ana";</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>$edad = 25;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>echo "Su nombre es " .$nombre . " y su edad es " .$edad;</b></i></div>
<div style="color: #666666; font-family: "Courier New",Courier,monospace;">
<i><b>?></b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0w46joRMz0FdjmrcEO5sTmJ4jPXXFJAtgHc85M3JLt-yVAQ1sI8YrUBEqVPsa-mX6aClaQHHJ2B4AaVb_d_At5M9bSmYMFH2_4cJRiA6unaBrtLgStyqPURRxySBlZInG__QGohLDSlg/s1600/variable2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="287" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0w46joRMz0FdjmrcEO5sTmJ4jPXXFJAtgHc85M3JLt-yVAQ1sI8YrUBEqVPsa-mX6aClaQHHJ2B4AaVb_d_At5M9bSmYMFH2_4cJRiA6unaBrtLgStyqPURRxySBlZInG__QGohLDSlg/s320/variable2.jpg" width="320" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En este ejemplo hemos mezclado cadenas de texto con variables.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Las cadenas de texto van entre comillas, y para agregar variables debemos agregar el signo de concatenación, que en PHP es el punto (.) Los espacios que dejamos entre las comillas son para que las cadenas de texto no aparezcan "pegadas" a las variables y se respeten los espacios.<br />
<br />
<b>Constantes.</b><br />
<br />
Las constantes son parecidas a las variables, pero estas no cambian su valor. Es decir, cuando les asignamos un valor, este permanece durante todo el programa.<br />
<b> </b><br />
Son útiles para declarar valores que sabemos que no van a cambiar.<br />
<br />
Se declaran usando la función <i>define</i>:<br />
<br />
<div style="color: #666666;">
<i><b><?php</b></i></div>
<div style="color: #666666;">
<i><b>define ("constante", "valorfijo");</b></i></div>
<div style="color: #666666;">
<i><b>printf (constante);</b></i></div>
<div style="color: #666666;">
<i><b>?></b></i></div>
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Con esto finalizamos el capítulo sobre variables y constantes.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En el siguiente hablaremos de los <a href="http://programador-apli.blogspot.com/2012/02/operadores.html">Operadores</a>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-42714772648848857892012-02-27T10:07:00.001-08:002012-03-26T11:47:18.330-07:00Instalar PHP en nuestra máquina<div style="color: black; font-family: "Courier New",Courier,monospace;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN2c8AwSnrUAdtzsc5lOvHIplxXmPNOGTOrelDryHBn0ObQzXdd-qpokater0KkTm1hteoa3ap1pQWTvXdwwYictCfgaPGuurXf57KNagGgD-AOm6t2i6kscxTz5Ifpq40f_Ir5-a2i5M/s1600/titulo_xampp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN2c8AwSnrUAdtzsc5lOvHIplxXmPNOGTOrelDryHBn0ObQzXdd-qpokater0KkTm1hteoa3ap1pQWTvXdwwYictCfgaPGuurXf57KNagGgD-AOm6t2i6kscxTz5Ifpq40f_Ir5-a2i5M/s1600/titulo_xampp.jpg" /></a></div>
<div style="text-align: center;">
<br /></div>
<br />
PHP es un lenguaje de lado servidor. Esto significa que el código PHP se procesa en el servidor web y devuelve el resultado al navegador en forma de HTML.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para poder trabajar en nuestro ordenador con PHP, necesitamos instalar un servidor web para trabajar en local (modo off-line).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
El servidor con el que trabajaremos será <a href="http://www.apache.org/">Apache</a>, un servidor gratuito, libre, y lo mejor de todo, muy potente y estable, presente en la gran mayoría de sitios web en Internet.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Pero no basta con instalar únicamente el servidor web, también necesitamos instalar el motor <a href="http://www.php.net/">PHP</a> y una base de datos para gestionar nuestros sitios web. Para la base de datos usaremos <a href="http://www.mysql.com/">mySQL</a>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Al final deberemos configurar a mano unos archivos para conectar Apache con PHP y estos con mySQL. Pero existen soluciones que permiten instalarnos todo esto ya configurado de forma automática. Son los llamados paquetes XAMPP.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
XAMPP significa:</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
X = cualquier sistema operativo</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
A = Apache</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
M = MySQL</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
P = PHP</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
P = Perl.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En línux el paquete suele llamarse LAMPP (L = Linux), y en Windows el paquete suele llamarse WAMPP (W = Windows).</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En windows consiste en un simple asistente de instalación.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
En linux basta con descargar el archivo desde <a href="http://www.apachefriends.org/en/xampp-linux.html#374">esta web</a> y descomprimirlo en la carpeta /opt.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Como yo trabajo con linux, voy a realizar el ejemplo con este, pero en Windows es igual de sencillo.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
1. Descargamos el archivo <b><i>xampp-linux-1.7.7.tar.gz </i></b></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
2. Abrimos una terminal y nos identificamos como root.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
3. Nos dirigimos al directorio donde descargamos el archivo. En mi caso /home/dani/Descargas.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
4. Tecleamos <i style="color: #666666;"><b>tar xvfz xampp-linux-1.7.7.tar.gz -C /opt</b></i></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Habremos instalado el paquete XAMPP en la carpeta /opt/lampp.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para iniciar el servidor solo tenemos que teclear<br />
<i style="color: #666666;"><b>/opt/lampp/lampp start</b></i>, y para detenerlo <i style="color: #666666;"><b>/opt/lampp/lampp stop</b></i>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
Para comprobar que la instalación se ha realizado correctamente, accedemos al servidor desde http://localhost.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div class="separator" style="clear: both; color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGtEVd_OeCp6HpmwdSmD62zE7Lt3uGkgZ57XFAZzbamL5aiQei-9SMMrrCQO8IVVMrTkXpm_JRbTeh-FaogbuJAKj41DfYBVOJHwzp7sQKVdVI-Xw9qhXzgQFtXOF9gPML0hIDitlkwSQ/s1600/xampp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGtEVd_OeCp6HpmwdSmD62zE7Lt3uGkgZ57XFAZzbamL5aiQei-9SMMrrCQO8IVVMrTkXpm_JRbTeh-FaogbuJAKj41DfYBVOJHwzp7sQKVdVI-Xw9qhXzgQFtXOF9gPML0hIDitlkwSQ/s320/xampp.jpg" width="320" /></a></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: center;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
Con esto finalizamos el capítulo de instalación de Apaque, PHP y MySQL.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace; text-align: left;">
En el próximo capítulo empezaremos con un poco de <a href="http://programador-apli.blogspot.com/2012/02/un-poco-de-sintaxis.html">Síntaxis</a>.</div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>
<div style="color: black; font-family: "Courier New",Courier,monospace;">
<br /></div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0tag:blogger.com,1999:blog-1511459546315590868.post-45325533706713512842012-02-26T07:11:00.001-08:002012-03-01T00:08:06.407-08:00Migración de Windows a Linux<div style="font-family: "Courier New",Courier,monospace;">
<div style="font-family: "Courier New",Courier,monospace;">
</div>
<div style="font-family: "Courier New",Courier,monospace;">
Recopilación de entrevistas realizadas por el programa <a href="http://www.youtube.com/user/redtves?feature=g-all-bul">Mundo Digital</a> a Paul Brown (Director de la revista <a href="http://www.linux-magazine.es/">Linux Magazine</a>), donde comentan información y curiosidades sobre el mundo Linux, ideal para aquellos que están pensando introducirse.</div>
<div style="font-family: "Courier New",Courier,monospace;">
</div>
<div style="font-family: "Courier New",Courier,monospace;">
Empezamos con la Migración de Windows a Línux.</div>
<div style="font-family: "Courier New",Courier,monospace;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<i>Parte 1</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/P6ikz3URLj0?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br />
<i>Parte 2</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/3D9X-oEvoEs?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br />
<i>Parte 3</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/rmlro4-zI44?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br />
<i>Parte 4</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/7r0e3WxG5oQ?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br />
<i>Parte 5</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/P1KQYnVhSf4?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
<br />
<i>Parte 6</i></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/7vr7DZZp9dw?feature=player_embedded' frameborder='0'></iframe></div>
<div style="font-family: "Courier New",Courier,monospace; text-align: center;">
</div>
</div>Danihttp://www.blogger.com/profile/00454210631551264906noreply@blogger.com0