clase 2 -lp

Post on 12-Dec-2015

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

hyuyuubi

TRANSCRIPT

CLASE 2

PROGRAMACIÓN ESTRUCTURADA:

Viene a ser una metodología en el cual se utiliza algoritmos para resolver un problema sin usar un computador.

ESTRUCTURA DE PROGRAMACIÓN:

Vienen a ser determinados pasos en forma lógica y ordenada para resolver un tipo de problema.

TIPOS DE ESTRUCTURAS:

Hay tres tipos de estructuras que se utilizan en el lenguaje de programación:

a) Estructura Secuencial.b) Estructura de decisión/selección c) Estructura de repetición

Algoritmos:

Son secuencias de procesos que nos permiten resolver un problema de computación.

-Diagramas de Flujos

- Pseudocódigos

Diagrama de flujo: Símbolos gráficos que representa una determinada acción.

Inicio/final

I/O INPUT/OUTPUT

Entrada /salida

Caja de proceso de calculo

Decisión

Flechas direcccionales

Conector de símbolos en una misma página

Conector de símbolos en la siguiente página

Ciclo de repetición controlada por una variable tipo contador

Ve Variable de control de repetición

Vi Vector inicial / 1

Vf Valor final ó último valor de repetición

Inc Variable contador o de incremento / 1 en 1

Símbolo es para referencial módulos o subprogramas.

Pseudocódigo (falso código) : Son palabras claves que simulan a una orden de programación , se usan para resolver problemas sin computadora .

Inicio, leer, ingresar, escribir, imprimir, hacer, para , si entonces, sino Fin. ( asignar)

InicioHacer x 0Para I 1 a S Hacer X I Fin de paraEscribir xFin

Estructura secuencial: Es aquella estructura donde los procesos de cálculo se realizar una tras otra en forma continua.

Estructura de Decisión Estas estructuras nos permiten comparar expresiones cuyos resultados n(verdaderos o falso) ibndicara en sentido del flujo del programa

VC | VA

Vf | InC

EJERCICIOS

1) PROGRAM decision1integer:: Rreal:: Vreal,parameter::PI=3.1415print*,"ingrese radio"read*,Rif (R>0) thenV=(4./3)*PI*R**3end ifPrint*,"volumen=",Vend program decision1

2)PROGRAM decision2INTEGER:: RREAL:: VREAL,PARAMETER::PI=3.1415PRINT*,"INGRESE RADIO"READ*,RIF (R>0) THENV=(4./3)*PI*R**3PRINT*,"VOLUMEN=",VELSEPRINT*,"RADIO NEGATIVO"END IFEND PROGRAM DECISION2

3) !PROGRAMA QUE HARA USO DE LA ESTRUCTURA DE DECISIONES .!MULTIPLES O ANIDADASprogram desicion1integer::Rreal::Vreal,parameter::pi=3.1416!r>0, R=0,R<0!los operaciones de relacion en Fortran son:!> mayor, <menor, >=mayor igual que !<=menor igual que , /=distinto !==igualprint*, "ingrese valor de radio"read*,rif (r>0) thenv=(4./3)*pi*r**3print*,"volumen de la esfera= ",velseif (r==0) thenprint*,"valor del radio es cero"else

if (r<0) then print*, "el radio es negativo"end if

end ifend ifend program desicion1

4)!PROGRAMA QUE HARA USO DE LA ESTRUCTURA DE DECISIONES .!MULTIPLES O ANIDADAS (FORMA ABREVIADA)program desicion1integer::Rreal::Vreal,parameter::pi=3.1416!r>0, R=0,R<0!los operaciones de relacion en Fortran son:!> mayor, <menor, >=mayor igual que !<=menor igual que , /=distinto !==igualprint*, "ingrese valor de radio"read*,rif (r==0) print*,"valor del radio es cero"if (r<0) then if (r>0) v=(4./3)*pi*r**3print*,"volumen de la esfera= ",velseif (r==0) then print*, "volumen de la esfera",v end program desicion1----------------------------------------------------------------------------------------------------------------------------

5) !PROBLEMA::ELABORE UN PROGRAMA QUE VISUALICE EL SIGUIENTE MENSAJE .!cuando se ingresa un valor numérico de tipo entero!si N es mayor que cero el mensaje sera "Numero es positivo"!si N es menor que cero el mensaje será "Numero es negativo"!si N es igual a cero el mensaje sera "Numero es cero"!Si ingresa otro caracter el teclado "Numero no valido"

PROGRAM condicionesINTEGER::NPRINT*,"Ingrese un numero"READ*,N,XIF(N>0) THENPRINT*,"Numero es positivo"elseIF(N<0) THENPRINT*,"Numero es negativo"elseIF(N==0) THENPRINT*,"Numero es cero"elsePRINT*,"Numero no válido"end ifend ifend ifend program condiciones---------------------------------------------------------------------------------------------------------------------------- !LOS OPERADORES LOGICO EN FORTRAN SON ! .and.es el y logico la conjunción!p q : p.and.q!v v : v!v f : f!f v : f!f f : f!los operadores logico en fortran son ! .and.es el o logico la disyunción!p q : p.or.q!v v : v!v f : v!f v : v!f f : f!los negacion logica el operador! .not.

-----------------------------------------------------------------------------------------------------------------------------------6)!Se tiene 4 notas de un alumno del curso de matemáticas I !ENCONTRAR EL PROMEDIO DE LAS 3 MEJORES NOTAS, ES DECIR!NO SE DEBE CONSIDERAR LA NOTA MAS BAJA! 18 15 5 12!PROMEDIO = (18+ 15 +12)/3!5 12 10 4 !PROMEDIO=(5+12+10)/3!11 01 12 15!promedio=(11+12+15)/3

PROGRAM calificacionesinteger::n1,n2,n3,n4 !las 4 calificacionesinteger::aux !variable auxiliarreal::promedioprint*,"ingrese las 4 calificaciones"read*,n1,n2,n3,n4aux=n1if (aux>n2) then aux=n2 else if (aux>n3) then aux=n3 else if (aux>n4) then aux=n4 end if end if end ifpromedio=(n1+n2+n3+n4-aux)/3

CORREGIDO

PROGRAM calificacionesinteger::n1,n2,n3,n4 !las 4 calificacionesinteger::aux !variable auxiliarreal::promedioprint*,"ingrese las 4 calificaciones"read*,n1,n2,n3,n4aux=n1if (aux>n2) then aux=n2end if

if (aux>n3) then aux=n3end if

if (aux>n4) then aux=n4 end if

promedio=(n1+n2+n3+n4-aux)/3.print*,"EL PROMEDIO =",promedioend program calificacionesprint*,"EL PROMEDIO =",promedioend program calificaciones

top related