01.03.2013 Views

Ejemplos para TC LENGUAJE C Programación de Computadores ...

Ejemplos para TC LENGUAJE C Programación de Computadores ...

Ejemplos para TC LENGUAJE C Programación de Computadores ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Ejemplos</strong> <strong>para</strong> <strong>TC</strong><br />

Nota: es <strong>de</strong> resaltar que en el if por ser solo una instrucción no es<br />

obligatorio encerrar esta instrucción <strong>de</strong>ntro <strong>de</strong> llaves, esto es solo una<br />

exigencia <strong>para</strong> 2 o más instrucciones.<br />

6. Calcular el mayor <strong>de</strong> un conjunto <strong>de</strong> números reales ingresados por el<br />

usuario<br />

#inclu<strong>de</strong><br />

#inclu<strong>de</strong><br />

main()<br />

{<br />

//variables<br />

int n,contador=1;<br />

float x,mayor;<br />

//Istrucciones<br />

clrscr();<br />

printf("Cuantos números <strong>de</strong>sea ingresar <strong>para</strong> encontrar el máximo: ");<br />

scanf("%d",&n);<br />

printf("Numero 1:");<br />

scanf("%f",&x);<br />

mayor=x;<br />

while(contadormayor)<br />

{<br />

mayor=x;<br />

}<br />

}<br />

printf("El mayor es %f",mayor);<br />

getch();<br />

return(0);<br />

}<br />

Nota: El programa presenta problemas cuando si digita un numero negativo<br />

<strong>para</strong> la cantidad <strong>de</strong> elementos. ¡Solucionarlo!<br />

7. Imprimir el factorial <strong>de</strong> un numero dado<br />

#inclu<strong>de</strong><br />

#inclu<strong>de</strong><br />

main()<br />

{<br />

//variables<br />

int n,i=1,fact=1;<br />

//Instrucciones<br />

<strong>Programación</strong> <strong>de</strong> <strong>Computadores</strong> Ing. Cesar Alberto Mayoral Ramírez

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!