Laboratorios CB412 2014-2.pptx

199
PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1 PROGRAMACION DIGITAL LABORATORIO N° 1 WILFREDO CUPE ROMÁN CICLO 2014-2 UNIVERSIDAD NACIONAL DE INGENIERIA FACULTAD DE INGENIERIA CIVIL

Transcript of Laboratorios CB412 2014-2.pptx

Page 1: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 1/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1

PROGRAMACION DIGITAL

LABORATORIO N° 1

WILFREDO CUPE ROMÁN

CICLO 2014-2

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 2: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 2/199

 COMPETENCIAS DEL CURSO1. Diseña programas para procesar datos, la generación de

información y su interpretación.

2. Razona, planea y construye una secuencia lógica de procesos

utilizando estructuras de selección e iteración.

3. Conoce nuevas técnicas y erramientas !ue permita suaplicación en la solución de pro"lemas.

#. Conoce y utiliza un lengua$e de programación a través de

pr%cticas de edición y e$ecución de programas estructurados.

&. Comprende el comportamiento de otros programas de

cómputo durante su utilización.

Las competencias 3, 4 y 5 se desarrollarán en las sesiones de

Laboratorio

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2

Page 3: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 3/199

Laboratorio N1

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3

Objetivos

1. Utilizar el PSeInt para la reai!n " e#e$i!n %e

Dia&ra'a( %e )l$#*.

2. C*n*er la( +aili%a%e( %el PSeInt para la,#e$i!n Pa(* a Pa(* " Pr$ea %e ,(rit*ri*.

Page 4: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 4/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4

Entorno del PSeInt

MENU

HERRAMIENTA

AREA !E

TRA"A#$

LINEA !EETA!$

%$MAN!$

Page 5: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 5/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 5

Cre!i"n de #i$r%s de &l'jo

AREA !E

TRA"A#$%$MAN!$

Page 6: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 6/199

Page 7: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 7/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )

O*erdores + &'n!iones

Page 8: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 8/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,

Eje!'!i"n del #i$r% de &l'jo

Page 9: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 9/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -

.entn de Eje!'!i"n

Page 10: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 10/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/

Eje!'!i"n *so *so

Per'ite realizar $n (e&$i'ient* '( %etalla%* %e la

e#e$i!n %el %ia&ra'a %e +l$#*/ *(eran%* en

tie'p* real la( in(tr$i*ne( " el *r%en en $e (e

e#e$tan.Ta'in (e p$e%e *(erar el *nteni%* %e ariale(

* e3pre(i*ne( %$rante el pr*e(*.

Page 11: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 11/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11

Eje!'!i"n *so *so

Page 12: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 12/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12

.entns de Eje!'!i"n *so *so

Page 13: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 13/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 13

Pr'eb de Es!ritorio

Per'ite *n+i&$rar $na tala *n $n *n#$nt* %e

ariale( * e3pre(i*ne( para $e (ean eal$a%a( en

a%a pa(* %e la e#e$i!n pa(* a pa(* " re&i(tra%a(

en %ia tala a$t*'tia'ente para analizar l$e&* lae*l$i!n %e l*( %at*( " el %ia&ra'a %e +l$#*.

Page 14: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 14/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 14

Pr'eb de Es!ritorio

Page 15: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 15/199

E!"r#i#io$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15

1. Se leen la( **r%ena%a( %e $n trin&$l* " $n

p$nt* '(. M*(trar (i e(te 5lti'* p$nt* e(t en elinteri*r * n* %el trin&$l*.

2. Sea +637 $na +$ni!n %e+ini%a en el interal* I890 /

:a;. Leer $n al*r real para 3/ $al$iera/ e in%iar

*n $n 'en(a#e (i 3 I " (i 3 I/ eal$ar en la∉ ∈+$ni!n " '*(trar el re($lta%*.

Page 16: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 16/199

E!"r#i#io$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(

<. Tele+!nia %el Per5 a %i(e=a%* l*( (i&$iente(

plane( para ($( $($ari*( %e tele+*n>a +i#a?

Deter'inar la anti%a% %e 'in$t*( lire( $e le

*rre(p*n%en (e&5n el plan $e eli#a/ el pa&* p*r

l*( 'in$t*( a%ii*nale(/ el '*nt* %e %e($ent* "

el '*nt* $e %ee pa&ar $n $($ari*. C*n(i%ere lap*(iili%a% $e el $($ari* n* ten&a $e pa&ar na%a

p*r$e ($( 'in$t*( *n($'i%*( "a e(tn

$iert*( p*r ($( 'in$t*( lire(.

Pln 0in Libres Costo *or %in di!ionl #s!to

1 <00 0.10 0@

2 200 0.0 @

< 100 0.0 10@

Page 17: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 17/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)

PROGRAMACION DIGITAL

LABORATORIO N° 2

WILFREDO CUPE ROMÁN

CICLO 2014-2

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

1,

Page 18: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 18/199

Laboratorio N2

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,

Objetivos

1. Utilizar el D, C para C*%i+iar/ C*'pilar "

,#e$tar $n pr*&ra'a.

2. )a'iliarizar(e *n l*( ele'ent*( %el len&$a#e

C

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 1-

Page 19: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 19/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-

Entorno del #E. C

MENU

HERRAMIENTA

AREA !E

TRA"A#$

LINEA !E

ETA!$

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 2/

Page 20: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 20/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2/

N$e* → Ari* )$ente

Pr*"et*

 Arir Pr*"et* * Ari*E

 Arir Ari* Reiente

Graar 

Graar C*'*E

Graar T*%*

Cerrar 

Cerrar T*%*

Pr*pie%a%e(I'p*rtar 

,3p*rtar 

I'pri'irE

C*n+i&$ra I'pre(i!n

Salir 

0en' &ile Ar!ivo6

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 21

Page 21: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 21/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 21

C*'pilar 

C*'pila el ari* at$al

,#e$tar Par'etr*(E

C*'pilar " ,#e$tar 

Re*n(tr$ir T*%*

Rei(ar Sint3i(

Li'piar Re($lta%*(

 Anli(i( %e Per+il

Reiniiar e#e$i!n %el pr*&ra'a

0en' E7e!'te Eje!'tr6

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 22

Page 22: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 22/199

Len$'je de Pro$r%!i"n C

C*n#$nt* %e in(tr$i*ne( $e (e e#e$tan %e

'*%* (e$enial.

,l ANSI C e( $n len&$a#e %e alt* niel/ e( %eire(t '$* '( era %el len&$a#e nat$ral.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 22

 ANSI? A'erian Nati*nal Stan%ar%( In(tit$te

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 23

Page 23: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 23/199

Ejer!i!io1

Da%*( n n5'er*( in&re(a%*( p*r tela%*/ e(riir

$n pr*&ra'a $e per'ita %eter'inar el 'a"*r %e

l*( n n5'er*(.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 23

,ntra%a Sali%a

n 'a"*r  n$'

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 24

Page 24: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 24/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 24

)

Leer 

n$'

i ← 2

Leer 

n/n$'

n$' F 'a"*r 

)in

,(riir 

'a"*r 

i ≤ n

i ← i 1

'a"*r ← n$'

Inii*

'a"*r ← n$'

)

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 25

Page 25: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 25/199

#ire!tivs del Pre8*ro!esdor 

int main(){

}

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 25

Inii*

)in

#include<stdio.h> ?  Inl$"e la lirer>a %e+$ni*ne( %e ,ntra%aSali%a %el ari* %e

aeera (t%i*.

#define PI 3.14159   ? De+ine la *n(tante

PI

Ter%inl

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2(

Page 26: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 26/199

#e!lr!i"n de .ribles

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2(

tio !a"iale$

ar arater 

int enter*l*n& enter* lar&*

+l*at p$nt* +l*tante

%*$le %*le prei(i!n

Co%entrios

//Comentario en una línea/*Comentario en

varias líneas*/

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2)

Page 27: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 27/199

Le!t'r 9 Es!rit'r

scanf(%fo"mato&'a")$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2)

,(riir 

.r 

Leer 

.r 

"intf(%fo"mato&'a")

$

Es*e!i:i!dores de

:or%to

*c  ca"+cte"

*d  ente"o*ld ente"o la",o*f  unto flotante*lf dole

"ecisi-n

n salto de l/neat taulado"

& dole comilla

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2,

Page 28: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 28/199

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 2,

,(pei+ia%*re( A%ii*nale(

,+et*

 An* H$(ti+ia a la %ereaPrei(i!n Re%*n%ea al n %e %ei'ale(

- H$(ti+ia a la iz$ier%a

+ M$e(tra el (i&n* %el al*r 

0 Llena *n er*( (e&5n el an*

Es*e!i:i!dores de &or%to

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 2-

Page 29: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 29/199

O*erdores

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 2-

 Arit'ti*(

S$'a

- Re(taJ M$ltipliai!n

Dii(i!n

@ Re(t* %ii(i!n entera

Inre'entale(

Inre'ent* en 1

-- Dere'ent* en 1

L!&i*(

KK

O Ne&ai!n

Pri'ari*(

6 7 Lla'a%a +$ni!n

9 ; In%ie %e arre&l*

. Mie'r* e(tr$t$ra

Per'iten realizar *perai*ne( en el pr*&ra'a.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3/

Page 30: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 30/199

O*erdores

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 3/

Relai*nale(

88 I&$al $e

Men*r $eF Ma"*r $e

8 Men*r * i&$al $e

F8 Ma"*r * i&$al $e

8 N* i&$al $e

De A(i&nai!n

8 A(i&nai!n (i'ple

8 A(i&nai!n ($'a-8 A(i&nai!n re(ta

J8 A(i&nai!n'$ltipliai!n

8 A(i&nai!n %ii(i!n

@8 A(i&nai!n re(t*

Per'iten realizar *perai*ne( en el pr*&ra'a.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 31

Page 31: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 31/199

Pro!esos

!a"0e"esion$

!a"0!a"2delta$!a"20delta$

!a"0!a"21$

!a"22$

a0*$

PROGRAMACION DIGITAL CB412 I CICLO 2014 2 31

vr  ← e3pre(i!n

vr  ← vr   %elta

vr  ← vr   1

 ←  Re(t* 2

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 32

Page 32: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 32/199

#e!isi"n

32

if(ondici-n){entencias $

}else {

entencias 6$

}

Condi!i"n )

; ;Sentenia( )Sentenia(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 33

Page 33: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 33/199

B'!le !ondi!i"n l ini!io

7hile(ondici-n){entencias$

}

Condi!i"n

Sentenia(

)

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 34

Page 34: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 34/199

B'!le !ondi!i"n l :inl

do {entencias$}7hile(ondici-n)$Condi!i"n

Sentenia(

)

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 35

Page 35: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 35/199

Eje%*lo de Codi:i!!i"n//Mayor de n numeros

#include<stdio.h>int main() {  int n'num'ma8o"'i$  "intf(In,"ese n: )$ scanf(*d'n)$"intf(In,"ese num1: )$ scanf(*d'num)$

  ma8o"0num$ i0$7hile (i<0n){

"intf(In,"ese num*d: 'i)$scanf(*d'num)$

  if (num>ma8o"){  ma8o"0num$}

  i22$  }

  "intf(;l ma8o" !alo": *dn'ma8o")$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3(

Page 36: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 36/199

Co%*il!i"n 6,3e$te → C*'pile7

Eje!'!i"n 6,3e$te → R$n7

,l ari* e#e$tale e( in%epen%iente %el D,.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3)

Page 37: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 37/199

Errores de Sint<7is

prrintf("\n Hola mundo ");

Errores de Eje!'!i"n

c=15/0; /*No tiene errores de

sintaxis*/

Errores L"$i!os

Si en vez de la instrucción:

a=b+c;hubiera escrito:

a=b*c;

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3,

Page 38: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 38/199

Ejer!i!io2

Da%*( l*( %at*( %e %*( ir$n+erenia(?C1x C1y r1 **r%ena%a( %el entr* " ra%i* %e

Cx Cy r la ir$n+erenia

Deter'inar (i e(ta( ir$n+erenia( (*n

TANG,NT,S/ S,CANT,S * (i'ple'ente n* a"

*ntat* entre ella(.

,ntra%a( Sali%aC13/ C1"/ r1 QTan&ente(

C23/ C2"/ r2 QSeante(

QN* a" *ntat*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 3-

Page 39: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 39/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4/

Page 40: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 40/199

E7*ort!i"n C

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 41

Page 41: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 41/199

#e*'r!i"n del Pro$r% C !on #E. C

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 42

Page 42: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 42/199

PROGRAMACION DIGITAL

LABORATORIO N° 3

WILFREDO CUPE ROMÁN

CICLO 2014-1

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 43

Page 43: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 43/199

Laboratorio N%

Objetivos1. Crear $n D) *n P(eInt " e3p*rtarl* a C

2. Dep$rar el pr*&ra'a *n el D, C

<. Utilizar )$ni*ne( Mate'tia(4. Utilizar Sentenia( %e ,#e$i!n?

,ntra%a " Sali%a Dei(i*ne(

B$le(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 44

Page 44: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 44/199

Da%a( la( **r%ena%a( 63/ "7 %e tre( p$nt*( %el

e#e %e $na arretera/ (e %e(ea %eter'inar l*(

ele'ent*( %e la $ra *riz*ntal %e ra%i* R.

631/ "17

632/ "27

63</ "<7R

Ejer!i!io= #& !on PseInt

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 45

Page 45: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 45/199

Ele%entos de 'n C'rv >ori?ontl

C$ra a la %erea∆ 8 n&$l* %e %e+le3i!n

R 8 ra%i* %e la $ra

T 8 l*n&it$% %e la ($tan&ente 8 R tan6∆27L.C. 8 l*n&it$% %e $er%a 8 2 R Sen*6∆27

, 8 %i(tania a e3terna 8 R 6Se6∆27 - 17

M 8 %i(tania %e la *r%ena%a 'e%ia 8 R 61 C*(6∆277

Fuente: Manual de Diseño Geométrico de Carreteras (DG - 2!"

P.I.

,

ML.C.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4(

Page 46: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 46/199

Ejer!i!io= #& !on PseInt

Da%a $na p*li&*nal aierta %e N rtie(/ (e %e(eaal$lar ($( n&$l*( %e %e+le3i!n θ1/ θ2/ ...

@

1 1

2 2

E E

N N

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4)

Page 47: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 47/199

,ntra%a( Sali%a

N teta6en &ra%*(7

31/"1

32/"23</"<

Sol'!i"n

a 8 632-31/ "2-"17

8 63<-32/ "<-"27

teta 8 ar* *(en*6a.6aJ77 6en ra%iane(7

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4,

Page 48: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 48/199

Eje%*lo de eje!'!i"n

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 4-

Page 49: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 49/199

&'n!iones 0te%<ti!s

,l ANSI C tiene $na ili*tea e(tn%ar %e

+$ni*ne( 'ate'tia(.

Se %ee inl$ir al *'ienz* %el pr*&ra'a el

ari* 'at. *n la (entenia?

#include<math.h>

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 5/

Page 50: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 50/199

)$ni!n De(ripi!n

%*$le sin6%*$le 37 Sen*637/ 3 en ra%iane(

%*$le !os6%*$le 37 C*(en*637%*$le tn6%*$le 37 Tan&ente637

%*$le sin6%*$le 37 ar* (en*637 en ra%iane(

%*$le !os6%*$le 37 ar* *(en*637%*$le tn6%*$le 37 ar* tan&ente637

&'n!iones Tri$ono%tri!s

 Argumento o parámetroTipo del valor devuelto

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 51

Page 51: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 51/199

)$ni!n De(ripi!n

%*$le *o6%*$le 3/

%*$le "7

De$ele el al*r %e 3"

%*$le e7*6%*$le 37 De$ele el al*r %e e3

%*$le lo$6%*$le 37 l*&arit'* neperian* %e 3

%*$le lo$1/6%*$le 37 l*&arit'* %ei'al %e 3

Poten!is + Lo$rit%os

 Argumento o parámetroTipo del valor devuelto

Page 52: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 52/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 53

Page 53: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 53/199

)$ni!n De(ripi!n

%*$le sin6%*$le 37 (en* iper!li*637/ 3 en

ra%iane(%*$le !os6%*$le 37 *(en* iper!li*637

%*$le tn6%*$le 37 tan&ente iper!lia637

&'n!iones i*erb"li!s

 Argumento o parámetroTipo del valor devuelto

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 54

Page 54: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 54/199

B'!les

M*%i+ian el +l$#* (e$enial en la e#e$i!n %el

pr*&ra'a.

Se %en*'inan B$le( " per'iten repetir la

e#e$i!n %e $n*( pr*e(*( $n %eter'ina%*n5'er* %e ee( * a(ta $e (e $'pla $na

*n%ii!n %e tip* l!&i* * arit'ti*.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 55

Page 55: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 55/199

Senten!i ile

Per'ite e#e$tar repeti%a'ente $na (entenia *

l*$e %e (entenia(/ 'ientra( (e $'pla $na

%eter'ina%a *n%ii!n.

7hile (condici-n) {

sentencia$}

*n%ii!n

(entenia

)

Page 56: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 56/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 5)

Page 57: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 57/199

Eje%*los

1. Cal$lar el MCD %e %*( n5'er*( $tilizan%* el

al&*rit'* %e ,$li%e(.

P*r e#e'pl* para 2<:: " 2W<?

,l MCD e( X1

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 5,

Page 58: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 58/199

2. Realizar $n pr*&ra'a $e en$entre el al*r %e

e *n $n err*r 'en*r  a 10-4/ %a%* $e el al*r

%el e3p*nenial para $n al*r %e 3 (e p$e%e

e3pre(ar 'e%iante la (erie?

  e38133223<<E..

<. Da%*( n n5'er*( in&re(a%*( p*r tela%*/

e(riir $n pr*&ra'a $e per'ita %eter'inar el

'a"*r " el 'en*r %e l*( n n5'er*(.

Eje%*los

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 5-

Page 59: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 59/199

PROGRAMACION DIGITAL

LABORATORIO N° 4

WILFREDO CUPE ROMÁN

CICLO 2014-1

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (/

Page 60: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 60/199

Laboratorio N4

ObjetivoRe(*ler e#erii*( pr*p$e(t*( pre(entan%*

Dia&ra'a %e )l$#* " C*%i+iai!n C.

Utilizar PSeInt " D, C.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (1

Page 61: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 61/199

Ejer!i!io1

Da%* $n n5'er* enter*? Deter'inar ($ anti%a% %e i+ra( Inertir el n5'er*

In%iar (i e( $n n5'er* api5a

,#e'pl*?

N5'er* 8 :XX:

Nr* %e i+ra( 8 :

N5'er* Inerti%*8 :XX:

Si e( api5a

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (2

Page 62: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 62/199

Ejer!i!io2

Cal$lar el %eter'inante %e $n &r$p* %e 'atrie(

(i'tria( %e *r%en <3<. C*n(i%erar $e la

anti%a% %e 'atrie( n* (e *n*e %e ante'an*.

,l in&re(* %e %at*( ter'inar $an%* (e in&re(e$na 'atriz $e n* (ea (i'tria.

Dar *'* re(p$e(ta(?

Canti%a% %e 'atrie(

,l 'a"*r %eter'inante

,l 'en*r %eter'inante

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (3

Page 63: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 63/199

Ejer!i!io3

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (4

Page 64: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 64/199

Se leen l*( rtie( %e $na p*li&*nal aierta *n

a(i(a( reiente(/ *n(i%eran%* *'* pri'er

rtie al 60/07/ a%e'( la( *r%ena%a( %e a%a

%*( rtie( *n(e$ti*( %een (er %e (i&n**p$e(t*(. La let$ra %e l*( rtie( ter'ina

$an%* $n rtie $'ple *n "t*l/ %*n%e t*l e(

la t*lerania le>%a p*r tela%*.

Se pi%e %eter'inar el rea t*tal %e l*( trin&$l*($e (e +*r'an *n el e#e .

Ejer!i!io4

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (5

Ej l

Page 65: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 65/199

,ntra%a Sali%a

t*l Area

32/"2

3</"<

0/0

32/"2

3</"<

7i 7i 7j

32/"2

3</"<

Eje%*loT*lerania 8 0.

 Area 8 S1S2S<S4SS:

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ((

Page 66: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 66/199

PROGRAMACION DIGITAL

LABORATORIO N° 5

WILFREDO CUPE ROMÁN

CICLO 2014-1

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ()

Page 67: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 67/199

Laboratorio N&

Objetivos

C*n*er la %e+inii!n %e ari*( tip* te3t*

Utilizar ari*( tip* te3t* para la entra%a " (ali%a Utilizar el D, C para la *%i+iai!n

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (,

Page 68: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 68/199

Ar!ivo Ti*o Te7to

,(ta +*r'a%* p*r $n *n#$nt* %e aratere(

ASCII *r&aniza%*( (e$enial'ente.

Utiliza'*( el ari* para entra%a "* (ali%a %el

pr*&ra'a.

Pro$r%Ar!ivo de

#tosENTRA#A

Ar!ivo de

Res'ltdosSALI#A

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 (-

Page 69: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 69/199

Tbl ASCII

)$ente? ttp?VVV.el*%i&*a(ii.*'.ar

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )/

Page 70: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 70/199

1 #e!lrr vrible &ILE

6I; =!a"a"chi$

2 Abrir el Ar!ivo

!a"a"chi0foen(a"chi!o' modo)$

M*%* Apert$ra

De(ripi!n

Qr Are $n Ari* para let$ra 6,NTRADA7

QV Crea $n Ari* para e(rit$ra 6SALIDA7

Qa Are $n Ari* para a=a%ir al +inal 6SALIDA7

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )1

Page 71: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 71/199

3 Leer +9o Es!ribir 

fscanf(!a"a"chi' %fo"mato&'!a"iale)$

f"intf(!a"a"chi' %fo"mato&' e"esi-n)$

4 Cerrr el Ar!ivo

fclose(!a"a"chi)$

fcloseall()$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )2

Page 72: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 72/199

:eo:vrGr!i6 (er er%a%er* (i (e alanz! el ,O) "

  (er )al(* (i a5n n* (e alanza.

H:eo:vrGr!i6 (er er%a%er* 'ientra( n* (e alane

  el ,O).

&in de Ar!ivo *r r!ivos de le!t'r

ne&ai!n

Ar!ivo

de

Le!t'r

inii*

,O)

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )3

Page 73: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 73/199

H:eo:vrGr!i6

(entenia(

)

Le!t'r del r!ivo 'sndo ile !on H:eo:6

7hile(?feof(!a"a"chi)){//Sentencias de Lectura…

}

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )4

Page 74: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 74/199

H:eo:vrGr!i6

(entenia(

)

Le!t'r del r!ivo 'sndo do ile !on H:eo:6

do {//Sentencias de Lectura…

} 7hile(?feof(!a"a"chi))$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )5

Page 75: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 75/199

Ejer!i!io1

Un ari* *ntiene la( **r%ena%a( 63/ "7 %e l*(p$nt*( %e $na p*li&*nal erra%a. Deter'inar (i e(

$na p*li&*nal !naa * *ne3a. N* (e *n*e

la anti%a% %e p$nt*(.

P*li&*nal.t3t

10,13

11,6

20,1217,21

9,23

5,16

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )(

Page 76: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 76/199

Ejer!i!io2

Se tiene re&i(tra%* la( 'arai*ne( %e $ne'plea%* 6+ea/ *ra %e entra%a " %e (ali%a7 en

el ari* Mara.t3t/ (e %e(ea &$ar%ar en *tr*

ari* la( *ra( traa#a%a( en el 'e(.

  Mara.t3t Y*ra(tra.t3t

2014-04-03 09:58:49

2014-04-03 21:04:45

2014-04-04 10:19:532014-04-04 18:31:02

2014-04-05 10:26:15

2014-04-05 18:30:53

……

2014-04-03 11:05:56

2014-04-04 8:11:09

2014-04-05 8:04:38……

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ))

Page 77: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 77/199

Ejer!i!io3

Un ari* *ntiene l*( pr*'e%i*( %e l*(

al$'n*( )IC. Se pi%e %eter'inar la anti%a% %e

apr*a%*(/ %e(apr*a%*( " %a%* $n !%i&*

in&re(a%* p*r tela%* '*(trar en pantalla ($pr*'e%i*.

Pr*'e%i*(201<2.t3t

codigo letra promedio

20090205 K 11.55320112053 C 11.559

20054511 08.506

……

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ),

Page 78: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 78/199

Ejer!i!io4

,(riir $n pr*&ra'a $e e(ria en $n ari* $n

trin&$l* *'* el %e la +i&$ra. ,l %at* %el pr*&ra'a

(er la alt$ra %el trin&$l*.

8

Trian&$l*.t3t

  !

  ! !

  ! ! ! !

!!!!!!!!!

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 )-

Page 79: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 79/199

PROGRAMACION DIGITAL

LABORATORIO N° (

WILFREDO CUPE ROMÁN

CICLO 2014-1

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,/

Page 80: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 80/199

Laboratorio N'

Objetivo1. B$le +*r 

2.  Arre&l* Lineal

<.  Arre&l* Bi%i'en(i*nal4. ,#erii*(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,1

Page 81: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 81/199

Senten!i :or 

Per'ite repetir $na (entenia * l*$e %e(entenia(/ 'ientra( (e $'ple $na %eter'ina%a

*n%ii!n.

fo"(inicial$ condici-n$ inc"emento){ sentencia$

}

(entenia

iniialZ *n%ii!nZ inre'ent*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,2

Page 82: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 82/199

.rible S'bindi!d

,( $na ariale $e al'aena $n *n#$nt* %e al*re( %el'i('* tip* %e %at*.

Ca%a al*r %el *n#$nt* (e i%enti+ia *n $n ($>n%ie

enter* 60/ 1/ 2/E7.

Ta'in (e le %en*'ina rre$lo.

Tip*(?

 Arre&l* Lineal? $n (*l* ($>n%ie 6et*r7J  Arre&l* Bi%i'en(i*nal? %*( ($>n%ie( 6'atriz7  Arre&l* M$lti%i'en(i*nal? tre( * 'a( ($>n%ie(

J Una a%ena %e aratere( e$iale a $n arre&l* lineal %e aratere(.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,3

Page 83: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 83/199

Arre$lo Linel

Tiene $n (*l* ($>n%ie.

Delarai!n? tip* n*'re[arre&l*9N ele'ent*(;Z

,#e'pl*? int 390;Z

390; 391; 392; E 394X;

0 ele'ent*(

($>n%ie

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,4

Page 84: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 84/199

Arre$lo Linel

Let$ra " ,(rit$ra?(an+6Q+*r'at*/Kele'ent*9i-(i'*;7Z

print+6Q+*r'at*/ele'ent*9i-(i'*;7Z

,#e'pl*?

(an+6Q@%/ K39i;7Z

print+6Q@%/ 39i;7Z

Leer 

3i

,(riir 

3i

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,5

Page 85: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 85/199

Ejer!i!io1

Da%* $n arre&l* %e n ele'ent*(/ %eter'inar la 'e%ia" la %e(iai!n e(tn%ar.

Entrds Slids

N

3i 6i← 1..N7

'e%ia%e(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,(

Page 86: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 86/199

#i$r% PSeInt

C di:i i" C

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,)

Page 87: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 87/199

Codi:i!!i"n C

/*Obtiene la media y desviacion de n números x*/ 

"i#cl$de%&tdio.'( 

"i#cl$de%mat'.'( 

i#t mai#)*

i#t #,i do$le &0,/100,media,d0,de&

  pri#t)#gre&e #: * &ca#)d,#*

  or )i1i%#i++*

 pri#t)/d: ,i* &ca#)l,/i*

&&+/i

 

  media&#

  or )i1i%#i++*

  dd+)/i-media*!)/i-media* 

  de&&rt)d)#-1**

  pri#t);edia 8.2l<#=e&iacio# 8.2l<#,media,de&*

  &>&tem)pa$&e*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,,

Ej i"

Page 88: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 88/199

Eje!'!i"n

#gre&e #:6

/1: 4

/2: 1

/3: 11

/4: 13

/5: 2

/6: 7 ;edia 6.33

=e&iacio# 4.89

?re&io#e $#a tecla para co#ti#$ar . . .

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 ,-

Page 89: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 89/199

Ejer!i!io2

Da%* $n arre&l* %e N ele'ent*(/ %eter'inar $al e(el al*r $e '( ee( (e repite " $nta( ee( (e

pre(enta.

Entrds Slids

N

3i 6i← 1..N7

'*%aee('*%a

31 32 3< 34 E 3N

;

;

 * ' p a r a i * ne (

 *'par a i*ne(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -/

Page 90: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 90/199

#i$r% PSeInt

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -1

Codi:i!!i"n C

Page 91: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 91/199

/*Obtiene la(s) moda(s) de n números enteros x*/ 

"i#cl$de%&tdio.'( i#t mai#)*

i#t i,@,A0,#,/100,moda100,ece&moda1,ece&

  pri#t)#gre&e #: * &ca#)d,#*

  or)i1i%#i++*

  pri#t)/d: ,i* &ca#)d,/i*

 

  or)i1i%#i++*

  ece&1

  or)@i+1@%#@++*  i)/i/@* ece&++

  i)ece&(ece&moda*

  A1

  ece&modaece&

Codi:i!!i"n C

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -2

Page 92: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 92/199

  modaA/i

 

  el&e

i)ece&ece&moda*

  A++

  modaA/i

   

  i)A!ece&moda%#*

  or)i1i%Ai++*

  pri#t)Ba moda d &e repite d

ece&<#,modai, ece&moda*

  el&e pri#t)o 'a> moda<#*

  &>&tem)pa$&e*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -3

Eje!'!i"n

Page 93: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 93/199

Eje!'!i"n

#gre&e #:13

/1: 9

/2: 8

/3: 7

/4: 1

/5: 4

/6: 9

/7: 5/8: 4

/9: 1

/10: 5

/11: 9

/12: 1

/13: 5

Ba moda 9 &e repite 3 ece&

Ba moda 1 &e repite 3 ece&

Ba moda 5 &e repite 3 ece&

?re&io#e $#a tecla para co#ti#$ar . . .

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -4

Page 94: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 94/199

Ejer!i!io3

Da%a( la( 'atrie( A " B %e 'Jn/ (e pi%e ($'arla($tilizan%* arre&l*( lineale(.

Entrds Slids

'/ n

 Ai 6i← 1..'Jn7

Bi 6i← 1..'Jn7

Ci 6i← 1..'Jn7

 A\

\←]*l6]+ila-17Jn

B\

\←]*l6]+ila-17Jn

nmmnnmnm

nnn

n

nmmnnmnm

nnn

n

 B B B

 B B B

 B B B

 A A A

 A A A

 A A A

*2)1(1)1(

221

21

*2)1(1)1(

221

21

...

............

...

...

...

............

...

...

     

 

 

 

 

+

     

 

 

 

 

+−+−

++

+−+−

++

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -5

Page 95: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 95/199

#i$r% PSeInt

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -(

Codi:i!!i"n C

Page 96: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 96/199

/*suma de matrices A(m*n) y B(m*n) usando

arreglos lineales*/ "i#cl$de%&tdio.'( 

i#t mai#)*

i#t i,@,A,m,#

  loat D100,E100,C100  pri#t)ro ila&: * &ca#)d,m*

  pri#t)ro col$m#a&: * &ca#)d,#*

  pri#t)D:<#*

  or)i1i%m!#i++* &ca#),Di*

  pri#t)E:<#*

  or)i1i%m!#i++* &ca#),Ei*

Codi:i!!i"n C

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -)

Page 97: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 97/199

 pri#t)C:<#*

  or)i1i%mi++* 

or)@1@%#@++*

  A@+)i-1*!#

  CADA+EA  pri#t)8.1,CA*

 

  pri#t)<#*

    &>&tem)pa$&e*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 -,

Eje!'!i"n

Page 98: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 98/199

Eje!'!i"n

 ro ila&: 3

 ro col$m#a&: 4

 D:

9 3 8 1

8 6 4 0

5 2 3 4

E:

5 7 2 39 6 1 1

4 9 3 7

C:

  14.0 10.0 10.0 4.0

  17.0 12.0 5.0 1.0

  9.0 11.0 6.0 11.0

?re&io#e $#a tecla para co#ti#$ar . . .

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 --

UNIVERSIDAD NACIONAL DE INGENIERIA

Page 99: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 99/199

PROGRAMACION DIGITAL

LABORATORIO N° (

WILFREDO CUPE ROMÁN

CICLO 2014-1

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1//

Page 100: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 100/199

Laboratorio N'

Objetivo1. Utilizar arre&l*( i%i'en(i*nale(

2. Utilizar +$ni*ne( " pa(* %e par'etr*( p*r

al*r 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/1

Page 101: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 101/199

Tiene %*( ($>n%ie(Delarai!n? tio mat"i@ABCfilasDABCcolumnasD$

,#e'pl*? int AEDA3ED$

!0 0 !0 1 !0 !0 #

!1 0

!1 1

!1

!1 #

!1# 0 !1# 1 !1# !1# #

+ila 0 →

+ila 1 →

+ila 1X →

E

*l 0

*l 1

*l 2

*l 2X

E

Arre$lo Bidi%ensionl

<0 *l$'na(

20+ila(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/2

Page 102: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 102/199

Le!t'r de Arre$lo Bidi%ensionl

scanf(fo"mato'mat"i@A#filaDA#colD)$

fscanf(file'fo"mato'mat"i@A#filaDA#colD)$

,#e'pl*?

scanf(*d' AiDAFD)$

fscanf(file'*d' AiDAFD)$

$%%rxi &

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/3

Page 103: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 103/199

Es!rit'r de Arre$lo Bidi%ensionl

"intf(fo"mato'mat"i@A#filaDA#colD)$

f"intf(file'fo"mato'mat"i@A#filaDA#colD)$

,#e'pl*?

"intf(*d' AiDAFD)$

f"intf(file'*d' AiDAFD)$

'cribirxi &

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/4

Page 104: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 104/199

Ejer!i!io

Da%a( la( 'atriz A %e nJn/ (e pi%e *nertirla atrian&$lar ($peri*r 'e%iante *perai*ne( ele'entale(

p*r +ila( " l$e&* al$lar ($ %eter'inante.

Entrds Slids

n

 Ai # i/ #← 1..n

 Ai # 6trian&$lar ($peri*r7

%et

nnnn

n

n

nnnnnn

n

n

 A

 A A

 A A A

 A A A

 A A A

 A A A

*

222

12111

*21

22212

12111

...00

............

...0

...

...

............

...

...

     

 

 

 

 ⇒

     

 

 

 

 

Sol'!i"n

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/5

Page 105: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 105/199

Sol'!i"n

Trian&$lar ($peri*r?

)ila Pi*te i ← 1n1

)ila M*%i+ia%a & ← i+1nc = &i/ii , ii ≠ 0

-ila& ← -ila& + c*-ilai

Deter'inante?

 

)ila Pi*te i=1

&=

'ila (odificada

nnnnnn

n

n

 A A A

 A A A

 A A A

*21

22212

12111

...

............

...

...

     

 

 

 

 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/(

a

Page 106: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 106/199

a

a

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/)

Page 107: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 107/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/,

Page 108: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 108/199

& i S b 6

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1/-

Page 109: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 109/199

&'n!iones S'b*ro$r%s6

PRORA0A

&JNCION 1

&JNCION 2

&JNCION 3

#I.I#IR

;

Un pr*&ra'a &ran%e * *'ple#* (e p$e%e %ii%ir en$na (erie %e '!%$l*( '( pe$e=*( " 'ane#ale(. A

a%a '!%$l* (e le lla'a +$ni!n.

La +$ni!n e( $na parte * '!%$l* %el pr*&ra'a $e

realiza $na tarea e(pe>+ia "* ret*rna $n al*r *'*

re($lta%*.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11/

Pr<%etros *sdos *or .lor

Page 110: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 110/199

Se pa(a $na *pia %el al*r %el par'etr* 6el *ri&inal

n* a'ia7.

@0alo"('…)$

alo"   ? n*'re %e la +$ni!n

'…   ? par'etr*(

@ ? reie el al*r ret*rna%* p*r la +$ni!n

Pr<%etros *sdos *or .lor 

C U,LT  ARe

t *r na $n 0 al*r  6 *p i*nal7

E

E

De+inii!n

alo"()ID A

C*pia %e  3

. l R t d

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 111

Page 111: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 111/199

.lor Retorndo

al*r $e ret*rna la +$ni!n *n la (entenia ret'rn

Si la +$ni!n n* ret*rna nin&5n al*r/ el tip* %e la

+$ni!n (er void v!o6

Psos *r 'tili?r &'n!iones

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 112

Page 112: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 112/199

Psos *r 'tili?r &'n!iones

Para $tilizar +$ni*ne( en n$e(tr* pr*&ra'a (e %een (e&$ir

l*( (i&$iente( pa(*(? Delarai!n/ Lla'a%* " De+inii!n.

#include<stdio.h>tio funcion(a"+met"os fo"males)$ &' !eclaraci(n

int main() {

  !a"iale 0 funcion(a"+met"osactuales)$

)' Llamado

…}tio funcion(a"+met"os fo"males){ 3' !e*inici(n

"etu"n !alo"$ Retorna +alor

}

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 113

Psos *r 'tili?r &'n!iones

Page 113: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 113/199

1 #e!lr!i"n tio funcion(a"+met"os fo"males)$

2 Ll%do !a"iale 0 funcion(a"+met"os actuales)$

3 #e:ini!i"n tio funcion(a"+met"os fo"males){

  …

  }D*n%e?

tip* ? tip* %el al*r ret*rna%* p*r la +$ni!n

+$ni!n ? N*'re %e la +$ni!nPar'etr*(+*r'ale(

? Par'etr*( $tiliza%*( en la %e+inii!n

Par'etr*( at$ale( ? Par'etr*( $tiliza%*( en el lla'a%*

ariale ? Reie el al*r ret*rna%*

Psos *r 'tili?r &'n!iones

Ej l 1

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 114

Page 114: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 114/199

Eje%*lo1

De+inir $na +$ni!n $e %a%* $n n&$l* en &ra%*( "'in$t*(/ ret*rne el n&$l* en ra%iane(.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`&ra% p*r al*r 6int7

'in p*r al*r 6int7

^La +$ni!n ret*rna $n al*r`

Si/ ret*rna el n&$l* en ra%iane(.tip* +l*at

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 115

# & PS I t

Page 115: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 115/199

#& PSeInt

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11(

Codi:i!!i"n1

Page 116: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 116/199

Eje%*lo2

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11)

Page 117: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 117/199

Eje%*lo2

De+inir $na +$ni!n $e eal5e el p*lin*'i*?  P637 8 an3

n  an-13n-1  E a23

2a13a0

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`a/n p*r re+erenia 6arre&l* +l*at7

n p*r al*r 6int7

3 p*r al*r 6+l*at7

^La +$ni!n ret*rna $n al*r`

Si/ ret*rna el p*lin*'i* eal$a%* en 3.

tip* +l*at

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11,

# & PSeInt

Page 118: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 118/199

#& PSeInt

PSeInt?

anD13n

  an3n-1

  E a23 a1

C?

an3n  an-13n-1  E a13 a0

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 11-

Codi:i!!i"n2

Page 119: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 119/199

)rreglo como par%metro*+ de elementos opcional

)rreglo como par%metro

*+ de elementos opcional

Eje%*lo3

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12/

Page 120: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 120/199

Eje%*lo3

De+inir $na +$ni!n $e e(ria en pantalla la l*n&it$%%e $na p*li&*nal erra%a %e n p$nt*( 63/ "7

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`n p*r al*r 6int7

31n p*r re+erenia 6arre&l* +l*at7

"1n

p*r re+erenia 6arre&l* +l*at7

^La +$ni!n ret*rna $n al*r`

Si/ ret*rna la l*n&it$% %e la p*li&*nal.

tip* +l*at

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 121

Codi:i!!i"n3

Page 121: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 121/199

!oid lon,itudoli(float A5ED'float 8A5ED'intn){

  float lon0E$ int i$

  An21D0AnD$ 8An21D08AnD$

  fo"(i01$ i<0n$ i22)

  lon0lon2sG"t(o7(AiDHAi21D') 2

  o7(8AiDH8Ai21D'))$

  "intf(on,itud 0 *.3lfn'lon)$}

Codi:i!!i"n3

Eje%*lo4

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 122

Page 122: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 122/199

Eje%*lo4

De+inir $na +$ni!n $e ret*rne la anti%a% %e +ila($e a" en $n ari* tip* te3t*.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`nin&$n*

^La +$ni!n ret*rna $n al*r`

Si/ ret*rna la anti%a% %e +ila(.tip* int

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 123

Codi:i!!i"n4

Page 123: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 123/199

int numfilas(){ 

6I; =,$ int conta0E$ cha" ca"$

  ,0foen(JKL.KMK'")$

  7hile(?feof(,)){  fscanf(,'*c'ca")$

  if(ca"00NnN) conta22$

  }

  fclose(,)$

  "etu"n conta21$

}

Codi:i!!i"n4

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 124

UNIVERSIDAD NACIONAL DE INGENIERIA

Page 124: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 124/199

PROGRAMACION DIGITALLABORATORIO N° )

WILFREDO CUPE ROMÁN

CICLO 2014-1

FACULTAD DE INGENIERIA CIVIL

Laboratorio N(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 125

Page 125: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 125/199

Laboratorio N (

Objetivo1. Utilizar +$ni*ne( " pa(* %e par'etr*( p*r

re+erenia.

2. Utilizar et*re( " 'atrie( *'* par'etr*(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12(

Pr<%etros *sdos *or Re:eren!i

Page 126: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 126/199

Se pa(a la %irei!n en 'e'*ria %el par'etr* 6el

*ri&inal p$e%e a'iar7.

@0Oefe"encia('…)$

alo"   ? n*'re %e la +$ni!n

'…   ? par'etr*(

@ ? reie el al*r ret*rna%* p*r la +$ni!n

* *

C U, LT  ARet * r na $n 0 al * r  6 * p i * nal 7 

E

E

De+inii!n

Oefe"encia(=)ID A

Direi!n en Me'*ria %e  3

Psos *r 'tili?r &'n!iones

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12)

Page 127: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 127/199

*

Para $tilizar +$ni*ne( en n$e(tr* pr*&ra'a (e %een (e&$ir

l*( (i&$iente( pa(*(? Delarai!n/ Lla'a%* " De+inii!n.

#include<stdio.h>tio funcion(=a"+met"os fo"males)$ &' !eclaraci(n

int main() {

  !a"iale 0 funcion(a"+met"osactuales)$

)' Llamado

…}

tio funcion(=a"+met"os fo"males){ 3' !e*inici(n

"etu"n !alo"$ Retorna +alor

}

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12,

Psos *r 'tili?r &'n!iones

Page 128: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 128/199

1 #e!lr!i"n tio funcion(=a"+met"os fo"males)$

2 Ll%do !a"iale0funcion(a"+met"os actuales)$

3 #e:ini!i"n tio funcion(=a"+met"os fo"males){

  …

  }D*n%e?

tip* ? tip* %el al*r ret*rna%* p*r la +$ni!n

+$ni!n ? N*'re %e la +$ni!nPar'etr*(+*r'ale(

? Par'etr*( p$nter*( en la %e+inii!n

Par'etr*( at$ale( ? Direi!n par'etr*( en el lla'a%*

ariale ? Reie el al*r ret*rna%*

*

Ejer!i!io1

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 12-

Page 129: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 129/199

Ejer!i!io1

Di(e=ar $na +$ni!n $e lea $n et*r %e nele'ent*(.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`3 p*r re+erenia 6arre&l* +l*at7

Jn p*r re+erenia 6int7

^La +$ni!n ret*rna $n al*r`

N*/ n " 3 (e ret*rnan *'* par'etr*( p*rre+erenia.

tip* *i%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 13/

#i$r% de &l'jo PSeInt

Page 130: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 130/199

LLAMADO 

DEFINICION 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 131

#i$r% de &l'jo CB412

Page 131: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 131/199

lee[et*r63/ Jn7

Leer 

Jn

i ← 1..Jn

Leer 

3i

)in

Inii*

i ← 1..n

lee[et*r63/ Kn7

,(riir 

3i

)in

LLAMADO 

DEFINICION 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 132

Codi:i!!i"n C

Page 132: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 132/199

)rreglo como par%metro

*+ de elementos opcional

Ejer!i!io2

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 133

Page 133: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 133/199

Ejer!i!io2

Di(e=ar $na +$ni!n $e intera'ie el *nteni%**'plet* %e %*( et*re( %e n %ei'ale(.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`a p*r re+erenia 6arre&l* +l*at7

a p*r re+erenia 6arre&l* +l*at7

n p*r al*r 6int7

^La +$ni!n ret*rna $n al*r`N*/ a " (e ret*rnan *'* par'etr*( p*r

re+erenia.

tip* *i%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 134

#i$r% de &l'jo PSeInt

Page 134: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 134/199

LLAMADO 

DEFINICION 

LLAMADO 

LLAMADO 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 135

#i$r% de &l'jo CB412

Page 135: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 135/199

intera'i*6a/ / n7

i ← 1..n

)in

Inii*

i ← 1..n

lee[et*r6a/ Kn7

,(riir ai / i

)in

t ← ai

ai ← i

i ← t

lee[et*r6/ Kn7

intera'i*6a/ / n7

LLAMADO 

DEFINICION 

LLAMADO 

LLAMADO 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 13(

Codi:i!!i"n C

Page 136: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 136/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 13)

Codi:i!!i"n C

Page 137: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 137/199

Ejer!i!io3

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 13,

Page 138: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 138/199

je ! ! o3

Di(e=ar $na +$ni!n $e lea $na 'atriz %e *r%en 'Jn.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`

 A p*r re+erenia 6arre&l* i%i'en(i*nal +l*at7J' p*r re+erenia 6int7

Jn p*r re+erenia 6int7

^La +$ni!n ret*rna $n al*r`

N*/ A/ ' " n (e ret*rnan *'* par'etr*( p*rre+erenia

tip* *i%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-213-

#i$r% de &l'jo PSeInt

Page 139: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 139/199

LLAMADO 

DEFINICION 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-214/

#i$r% de &l'jo3

Page 140: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 140/199

lee['atriz6J+/ J/ a7

Leer 

J+ / J

i ← 1..J+ 

Leer 

ai #

)in

Inii*

lee['atriz6K'/ Kn/ a7

 # ← 1..J

i ← 1..'

,(riir 

ai #

)in

 # ← 1..n

LLAMADO 

DEFINICION 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2141

Codi:i!!i"n C

Page 141: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 141/199

(atriz como par%metro

*+ de filas opcional

Ejer!i!io4

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2142

Page 142: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 142/199

j

Di(e=ar $na +$ni!n $e '$ltipli$e %*( 'atrie( A6'Jn7 " B6nJp7.

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n` A p*r re+erenia 6arre&l* i%i'en(i*nal +l*at7

B p*r re+erenia 6arre&l* i%i'en(i*nal +l*at7

C p*r re+erenia 6arre&l* i%i'en(i*nal +l*at7

'/ n/ p p*r al*r 6int7^La +$ni!n ret*rna $n al*r`

N*/ C (e ret*rna *'* par'etr* p*r re+erenia

tip* *i%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2143

#i$r% de &l'jo4Inii*

DEFINICIONLLAMADO 

Page 143: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 143/199

'$ltiplia6A/B/C/'/n/p7 lee['atriz6A/K'/Kn7

lee['atriz6B/Kn/Kp7

'$ltiplia6A/B/C/'/n/p7

i ← 1..'

,(riir 

Ci #

)in

 # ← 1..n

i ← 1..'

)in

 # ← 1..p

\ ← 1..n

Ci # ←

 0

Ci # ← Ci #  Ai \J B\ #

LLAMADO 

DEFINICION 

LLAMADO 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2144

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 144: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 144/199

PROGRAMACION DIGITALLABORATORIO N° ,

WILFREDO CUPE ROMÁN

CICLO 2014-1

FACULTAD DE INGENIERIA CIVIL

Laboratorio N)

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2145

Page 145: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 145/199

abo a o o )

Objetivos1. Re(*ler e#erii*( $tilizan%* +$ni*ne(.

2. Intr*%$i!n a la Re$r(ii%a%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-214(

Ejer!i!io1

Page 146: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 146/199

I'pri'ir la 'atriz en $n ari*.

Re(*ler $tilizan%* +$ni*ne(.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 14)

Ejer!i!io2

Page 147: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 147/199

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 14,

Re!'rsividd

Page 148: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 148/199

Una )$ni!n e( re$r(ia $an%* (e lla'a a (i'i('a.

P*r e#e'pl*/ el +at*rial %e n (e p$e%e al$lar *n

$na +$ni!n re$r(ia?

n! = n*(n-1)*(n-2)*…*2*1

=

>−=01

0)1(*)(n

nn fact nn fact 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 14-

Ejer!i!io1

Page 149: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 149/199

Cal$lar en +*r'a re$r(ia el '3i'* *'5n %ii(*r %e

%*( n5'er*(

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`

a p*r al*r 6int7

p*r al*r 6int7^La +$ni!n ret*rna $n al*r`

Si/ ret*rna el MCD %e a " .

tip* int

=

>=

0%

0%)%,(),(

bab

bababmcd bamcd 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15/

#i$r% 0C#

Page 150: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 150/199

'%6a/7

)in

' ← 

ret$rn '

' ← '%6a/7

,(riir 

'

' ← '%6/a@7

Leer 

a/

Inii*

)in

LLAMADO 

DEFINICION 

LLAMADO 

RECURSIVO 

a@F0&.

FUNCION RINCIAL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 151

Ejer!i!io2

Page 151: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 151/199

Cal$lar 3n  en +*r'a re$r(ia/ 3 %ei'al " n enter*

p*(iti*

Plnte%iento

^_$e par'etr*( nee(ita la +$ni!n`

3 p*r al*r 6+l*at7

n p*r al*r 6int7^La +$ni!n ret*rna $n al*r`

Si/ ret*rna 3n.

tip* %*$le

=

>−=

01

0)1,(*),(

n

nn x pot  xn x pot 

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 152

#i$r% Poten!i

Page 152: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 152/199

p*t63/n7

)in

p ← 1

ret$rn p

p ← p*t63/n7

,(riir 

p

nF0

p ← 3Jp*t63/n-17

Leer 

3/ n

Inii*

)in

LLAMADO 

DEFINICION 

LLAMADO 

RECURSIVO 

&.

FUNCION RINCIAL

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 153

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 153: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 153/199

PROGRAMACION DIGITALLABORATORIO N° -

WILFREDO CUPE ROMÁN

CICLO 2014-1

FACULTAD DE INGENIERIA CIVIL

Laboratorio N*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 154

Page 154: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 154/199

Objetivo1. Utilizar a%ena %e aratere(.

2. Utilizar +$ni*ne( para a%ena(.

Cden de Cr!teres

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 155

Page 155: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 155/199

Una a%ena e( $n arre&l* %e aratere(.

#e!lr!i"n=

cha" cadenaA#ca"acD=%!alo" inicial&$

,#?cha" cadA3ED0%ola Qundon&$

,l arter n$l* 6.E7 in%ia el +inal %e la a%ena.

#na constante caracter se encierra entre comilla sim$le%

#na constante cadena se encierra entre doble comilla%

cad: o l a Q u n d o n E0 1 2 < 4 : W X 10 11

12 aratere(

Le!t'r de Cdens

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15(

Leer 

Page 156: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 156/199

a%

Lee a(ta en*ntrar e(pai* * (alt* %e l>nea.

cha" cadA3ED$

scanf(*s' cad)$ //por teclado, sin &

fscanf(,'*s' cad)$ //de archivo, sin &

Lee a(ta en*ntrar (alt* %e l>nea

cha" cadA3ED$,ets(cad)$ //por teclado

f,ets(cad'#ca"acte"es',)$ //de archivo

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15)

,(riir

Es!rit'r de Cdens

Page 157: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 157/199

cha" ca"A3ED$

"intf(*s' cad)$ //en pantalla

f"intf(h'*s' cad)$ //en archivo

,(riir 

a%

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15,

&'n!iones de Cdens

Page 158: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 158/199

Se %ee inl$ir en el pr*&ra'a? #include<st"in,.h>

)$ni!n De(ripi!n

st"len(cad) Ret*rna la l*n&it$% %e a%. N* (e

$enta el n$l*.

st"c8(cad1'cad)

C*pia a%2 en a%1.

st"cat(cad1'

cad)Une a%1 *n a%2.

st"cm(cad1'cad)

C*'para a%1 *n a%2.0 (i a%1a%2

Ret*rna 80 (i a%18a%2{

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 15-

#include<stdio.h>

Eje%*lo !on &'n!iones de Cdens

Page 159: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 159/199

#include<stdio.h>#include<st"in,.h>

int main(){ cha" aA5ED'noA5ED'anA1EED$ int n$ "intf(Jellidos: )$ ,ets(a)$ "intf(Bom"es: )$ ,ets(no)$

 st"c8(an'a)$ st"cat(an' )$ st"cat(an'no)$ "intf(*s *d ca"acte"esn'an' st"len(an))$ n0st"cm(a'no)$ if(n>E)  "intf(*s>*sn'a'no)$ else if(n<E) "intf(*s<*sn'a'no)$ 

else "intf(*s0*sn'a'no)$//n=0}

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(/

Eje!'!i"n

Page 160: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 160/199

 Dpellido&: ?FGFH BI?FH

 omre&: JD CDGBIL

?FGFH BI?FH JD CDGBIL 23 caractere&

?FGFH BI?FH(JD CDGBIL?re&io#e $#a tecla para co#ti#$ar . . .

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(1

Ejer!i!io1

Page 161: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 161/199

Da%a $na a%ena in&re(a%a p*r tela%*/ %eter'inar(i e( pal>n%r*'a 6$n pal>n%r*'* e( $na palara $e

(e lee i&$al en %*( (enti%*(/ ,#e'pl*? arepera/ Ana/

et.7.

n0Ri0E'1'…'R

cad: a " e … … … … … e " a E0 1 2 < E i n8i81 n-< n-2 n-1 n

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(2

Sol'!i"n1

Page 162: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 162/199

…conta0E$ //cuenta letras diferentesn 0 st"len(cad)$fo"(i0E$ i<0(nH1)S$ i22)

if(cadAiD?0cadAnHiH1D) conta22$

cad: a " e … … … … … e " a E0 1 2 < E i n8i81 n-< n-2 n-1 n

n aratere(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(3

Ejer!i!io2

Page 163: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 163/199

Leer $na +ra(e " i($alizar a%a palara (e&$i%a %eln5'er* %e letra( $e la *'p*nen. P*r e#e'pl*?

'ta fi%ta patria tom% conmod%racin

Se '*(trar>a?

'ta 5fi%ta

pacua tom% 2con 3mod%racin 1020 ar.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(4

Sol'!i"n2

Page 164: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 164/199

)ra(e? 'ta fi%ta patria tom% conmod%racin

Pri'er* la +ra(e (e &$ar%a en $n ari*?

)ra(e.t3t

L$e&* (e lee %el ari* palara p*r palara?

7hile(?feof(,)){

  fscanf(,'*s' cad)$  "intf(*HEs *dn'cad' st"len(cad))$

}

;stas fiestas ascuas tome con mode"aci-n

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(5

Ejer!i!ios Pro*'estos

Page 165: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 165/199

Da%a $na a%ena le>%a p*r tela%*/ *nertir la( letra('in5($la( a 'a"5($la(.

Da%a $na a%ena le>%a p*r tela%*/ inertir el *r%en %e

la( letra( %e a%a palara.

Da%* $n ari*/ leer p*r tela%* $na a%ena "

%eter'inar $anta( ee( (e repite la a%ena en el

ari*.

Da%* $n ari*/ leer p*r tela%* %*( a%ena(/ $(ar la

pri'era a%ena en el ari* " ree'plazarla p*r la

(e&$n%a a%ena.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1((

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 166: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 166/199

PROGRAMACION DIGITALLABORATORIO N° 1/

WILFREDO CUPE ROMÁN

CICLO 2014-1

FACULTAD DE INGENIERIA CIVIL

Laboratorio N*

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1()

Page 167: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 167/199

Objetivo1. Utilizar arre&l*( %e a%ena(

2. De(arr*llar apliai*ne( *n a%ena(

Arre$lo de Cdens

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(,

Page 168: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 168/199

,( $n arre&l* %*n%e a%a ele'ent* e( $na a%ena.

#e!lr!i"n=

cha" a""e,loA#filDA#colD0{!alo" inicial}$

D*n%e?

#fil   8 nr*. %e +ila( * nro% de cadenas.

#col   8 nr*. %e *l$'na( * nro% de caracteres

  de las cadenas.

{!alo" inicial} 8 al*re( iniiale( *pi*nale(.

Co%o ve!tor de !dens

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1(-

Page 169: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 169/199

cha" AEDA3ED0{ola'Qundo'T41I'n}$/: ola ;$#do CE412 <# … …

0 1 2 < E 1X

0 ola

1 ;$#do

2 CE412

< <#E …

1X …

32

<0 ar

   2   0   

  a   %  e  n  a  (

Co%o %tri? de !r!teres

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)/

Page 170: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 170/199

Ta'in (e p$e%e repre(entar *'* $na 'atriz %earatere(.

cha" AEDA3ED0{ola'Qundo'T41I'n}$0 1 2 < 4 E 2X

0 o l a <0 … … …

1  ; $ # d o <0 … …

2 C E 4 1 2 <0 …

< <# <0 … … … … … …E … … … … … … … …

1X … … … … … … … …

32

32

0 ola

1 ;$#do

2 CE412

< <#E …

1X …

<0 ar

Le!t'r del Arre$lo de Cdens

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)1

Page 171: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 171/199

Se lee ele'ent* p*r ele'ent*.

Lee a(ta en*ntrar e(pai* * (alt* %e l>nea&ca#)&, /i* //por teclado 

&ca#)g, &, /i*//de archivo 

Lee a(ta en*ntrar (alt* %e l>nea

get&)/i* //por teclado 

get&)/i,"caractere&,g* //de archivo 

Leer 

3i

Es!rit'r de Arre$lo de Cdens

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)2

Page 172: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 172/199

Se e(rie ele'ent* p*r ele'ent*.

 pri#t)&, /i* //en pantalla

pri#t)g,&, /i* //en archivo 

,(riir 

3i

Ejer!i!io1

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)3

Leer n a%ena( p*r tela%* " *r%enarla( al+atia'ente.

Page 173: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 173/199

Leer n a%ena( p*r tela%* " *r%enarla( al+atia'ente.

P*r ,#e'pl*?

1 ;IGD 

2 FLCDBDMF

< CIGMFH

4 JFDCDGBI

E …

n EIBI

1 EIBI

2 CIGMFH

< FLCDBDMF

4 JFDCDGBI

E …

n ;IGD 

ORD,NAR

Sol'!i"n1

/*Ordena n cadenas*/

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)4

Page 174: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 174/199

#include<stdio.h>

#include<st"in,.h>int main(){cha" A5EDA3ED'tA3ED$ int i'F'n$ "intf(B"o de cadenas: )$ scanf(*d'n)$,etcha"()$ //para el salto de linea

 fo"(i01$i<0n$i22){  "intf(adena*d :'i)$ ,ets(AiD)$ } /*Ordena x burbua alfabeticamente*/ fo"(i01$i<n$i22)  fo"(F01$F<0nHi$F22)//de menor a mayor  if(st"cm(AFD'AF21D)>E){  st"c8(t'AFD)$ st"c8(AFD'AF21D)$st"c8(AF21D't)$

  }  fo"(i01$i<0n$i22) "intf(*d *sn'i'AiD)$

Ejer!i!io2

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)5

Da%a $na +ra(e le>%a p*r tela%*/ (e pi%e aer $n

Page 175: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 175/199

a%a $ a a(e e %a p* te a%*/ (e p %e ae $

pr*&ra'a $e &enere el ari* Palara(.t3t/ *n la(palara( en 'a"5($la( " en *r%en al+ati*.

P*r e#e'pl*?

,(ta( +ie(ta( Patria( TOM, *n '*%erai!nPalara(.t3t

CON

,STAS

)I,STASMOD,RACION

PATRIAS

TOM,

Sol'!i"n2/*!ercicio " de cadenas*/#include<stdio h>

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)(

Page 176: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 176/199

#include<stdio.h>

#include<st"in,.h>int main(){cha" A5EDA3ED'c'tA3ED$ int i0E'n'F$ 6I; =,$ "intf(6"ase: )$ do {i22$

  scanf(*s*c'AiD'c)$  } 7hile(c00N N)$ n0i$ //#aso a mayusculas

 fo"(i01$i<0n$i22)  fo"(F0E$F<st"len(AiD)$F22){  c0AiDAFD$  if(c>0NaN  c<0N@N) c0cH3$  AiDAFD0c$

}

Sol'!i"n2

/*Ordena x burbua alfabeticamente*/

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1))

Page 177: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 177/199

 fo"(i01$i<n$i22)  fo"(F01$F<0nHi$F22)//de menor a mayor  if(st"cm(AFD'AF21D)>E){  st"c8(t'AFD)$  st"c8(AFD'AF21D)$

  st"c8(AF21D't)$  } ,0foen(ala"as.tt'7)$ fo"(i01$i<0n$i22)

  f"intf(,'*d *sn'i'AiD)$fclose(,)$ "intf(e c"eo ala"as.ttn)$ s8stem(ause)$}

Ejer!i!ios Pro*'estos

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1),

Page 178: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 178/199

Da%* $n ari*/ leer p*r tela%* $na a%ena "%eter'inar $anta( ee( (e repite la a%ena

en el ari*.

Da%* $n ari*/ leer p*r tela%* %*( a%ena(/$(ar la pri'era a%ena en el ari* "

re'plazarla p*r la (e&$n%a a%ena.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1)-

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 179: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 179/199

PROGRAMACION DIGITALLABORATORIO N° 11

WILFREDO CUPE ROMÁN

CICLO 2014-1

Laboratorio N11

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,/

Page 180: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 180/199

Objetivo1. De+inir $n tip* %e %at*( Re&i(tr*( 6(tr$t7

2. Utilizar ariale( tip* Re&i(tr*(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,1

Proble% Pro*'esto

Yaer $n pr*&ra'a $e ree(ria el *nteni%* %e $n ari*

Page 181: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 181/199

Agenda.txt *r%enn%*l* (e&5n +ea " *ra. N* (e *n*e el

n5'er* %e l>nea( %el ari*. Se re*'ien%a $tilizar $n !%i&*

$e +ailite el *r%ena'ient*/ *teni%* a partir %e la +ea "

*ra?

)ea " *ra ? DD-MM-AAAA ?''C!%i&* ? AAAAMMDD''

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,2

Estr'!t'rs o Re$istros

Page 182: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 182/199

Una e(tr$t$ra e( $n tip* %e %at*( *'p$e(t* p*r

ele'ent*( %en*'ina%*( a'p*(.

L*( a'p*( per'iten al'aenar in+*r'ai!n "

p$e%en (er %e %i+erente( tip*( %e %at*(.

Psos *r 'tili?r Estr'!t'rs

1. De+inir $na e(tr$t$ra 6alia( " a'p*(7

2. Delarar $na ariale tip* e(tr$t$ra

Se p$e%e $tilizar el alia( para %elarar la ariale

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,3

1 #e:ini!i"n de l Estr'!t'r

Page 183: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 183/199

Se p$e%e $tilizar el alia( para %elarar la ariale

en *tra (entenia.

st"uct alias{

 tio1 camo1$tio camo$

… …

}$

2 #e!lr!i"n de .rible

st"uct alias !a"iale$

alias

campo1 campo2   …

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,4

Eje%*lo

Page 184: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 184/199

st"uct datos{

 cha" codaA11D$

cha" aenomA4ED$

int c"eda$

 float "om$

}$

st"uct datos alu1' alu$

datos

coda

  apeno

m   promcredap

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,5

A!!eso los !%*os de 'n Estr'!t'r

Page 185: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 185/199

Para ae%er a la in+*r'ai!n &$ar%a%a en $na

e(tr$t$ra/ p*%e'*( aer $(* %e %*( *pera%*re(?

1.-,l *pera%*r p$nt* 6.7

!a"iale.camo

2.-,l *pera%*r p$nter* +lea 6-F7

!a"ialeunte"oH>camo

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,(

A!!eso los !%*os de 'n Estr'!t'r

Page 186: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 186/199

Eje%*los=

st"c8(alu1.coda' %E13EEE1J&)$st"c8(alu1.aenom' %Pe"e@HQanuel&)$alu1.c"eda01EE$

alu1."om015.U$

Para $tilizar el *pera%*r +lea/ %ee'*( aer $(*

%e p$nter*(.

st"uct datos =t"$t"0alu1$st"c8(t"H>coda' %E13EEE1J&)$t"H>c"eda01EE$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,)

Asi$n!i"n dire!t

Page 187: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 187/199

D*( ariale( e(tr$t$ra %el 'i('* tip* p$e%en

a(i&nar(e %ireta'ente.

st"uct datos alu1' alu$…

alu0alu1$Le!t'r + Es!rit'r

,( a'p* p*r a'p*/ $tilizan%* el *pera%*r p$nt*.

scanf(%*s&'alu1.coda)$,ets(alu1.aenom)$scanf(%*d *f&'alu1.c"eda' alu1."om)$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,,

Ejer!i!io Pro*'esto

Page 188: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 188/199

Un ari* *ntiene la (i&$iente in+*r'ai!n %e l*(

al$'n*( %e la )IC? !%i&*/ apelli%*( " n*'re(/

r%it*( apr*a%*( " pr*'e%i* p*n%era%*.

Utilizan%* ariale( tip* (tr$t/ leer el ari* " '*(trar

en pantalla l*( %at*( %el al$'n* *n 'a"*r " 'en*r

pr*'e%i*.

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1,-

UNIVERSIDAD NACIONAL DE INGENIERIAFACULTAD DE INGENIERIA CIVIL

Page 189: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 189/199

PROGRAMACION DIGITALLABORATORIO N° 12

WILFREDO CUPE ROMÁN

CICLO 2014-1

Laboratorio N12

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-/

Page 190: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 190/199

Objetivo1. De+inir $n tip* %e %at*( Re&i(tr*( 6(tr$t7

2. Utilizar arre&l*( %e Re&i(tr*(

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-1

t t li l A# l t D

Arre$lo de Estr'!t'rs

Page 191: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 191/199

st"uct alias a""e,loA#elementosD$

st"uct datos A5ED$

…scanf(%*s&'AiD.coda)$,ets(AiD.aenom)$scanf(%*d *f&'AiD.c"eda' AiD."om)$

xi

coda  apeno

m  promcredap

L t t % +i li % l l

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-2

#e:ini!i"n de l Estr'!t'r

Page 192: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 192/199

La e(tr$t$ra (e %e+ine *n $n alia( " (e %elara la

ariale.

st"uct alias{

 tio1 camo1$tio camo$

… …

} !a"iale$

alias

campo1 campo2   …

, il % +i i l t t i li % l l

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-3

#e:ini!i"n de l Estr'!t'r

Page 193: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 193/199

,( p*(ile %e+inir la e(tr$t$ra (in alia( " %elarar la

ariale.

st"uct{

 tio1 camo1$tio camo$

… …

} !a"iale$

variable

campo1 campo2   …

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-4

Ejer!i!io1

Page 194: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 194/199

Leer p*r tela%* la (i&$iente in+*r'ai!n %e nal$'n*(?

C!%i&*  Apelli%*( " N*'re(

Cr%it*( Apr*a%*( Pr*'e%i*

G$ar%ar l* le>%* en $n ari*. Utilizar $n arre&l*

%e e(tr$t$ra(.

Codi:i!!i"n1/*!emplo con re$istros o estructuras*/

#include<stdio.h>

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-5

Page 195: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 195/199

#include<stdio.h>

st"uct datos //%'efinicion {cha" codaA11D$ cha" aenomA4ED$

int c"eda$ float "om$

 }$ //()ui punto y coma

int main()

{ //" 'eclaracion de variable

  st"uct datos A5ED$ int i'n$ 6I; =,$

  "intf(n: )$ scanf(*d'n)$

  fo"(i01$i<0n$i22){

  "intf(Jlumno*dn'i)$  "intf(P"omedio: )$ scanf(*f'AiD."om)$

  "intf(odi,o: )$ scanf(*s'AiD.coda)$

,etcha"()$ //#ara el salto de linea

  "intf(Jellidos 8 Bom"es: )$,ets(AiD aenom)$

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-(

Page 196: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 196/199

,ets(AiD.aenom)$

  "intf("editos: )$ scanf(*d'AiD.c"eda)$  }

  ,0foen(JVQBL.KMK'7)$

  fo"(i01$i<0n$i22){

  f"intf(,'*s 'AiD.coda)$  f"intf(,'*H4Es'AiD.aenom)$

  f"intf(,'*E5.f 'AiD."om)$

  f"intf(,'*dn'AiD.c"eda)$

 }

 fclose(,)$ s8stem(ause)$

}

#: 5

 Dl$m#o1

?romedio: 15 8

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-)

Eje!'!i"n1

Page 197: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 197/199

?romedio: 15.8

Codigo: 20120101D 

 Dpellido& > omre&: ?FGFH BI?FH JD CDGBILCredito&: 120

 Dl$m#o2

?romedio: 10.9

Codigo: 20100101E

 Dpellido& > omre&: GD;IL FLMGD=D KFN ODLMI

Credito&: 100

 Dl$m#o3

?romedio: 14.6Codigo: 20110101C

 Dpellido& > omre&: LDMDPI BBFFBBL JILF

Credito&: 200

 Dl$m#o4

?romedio: 13.7

Codigo: 20100101=

 Dpellido& > omre&: IMFGI ;IMFHD DBFQD=FG 

Credito&: 190

 Dl$m#o5

?romedio: 19.9

Codigo: 20130101F

 Dpellido& > omre&: ;IRD CDDD CDGBIL DGMGI

Credito&: 200

?re&io#e $#a tecla para co#ti#$ar . . .

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1-,

ALJ0NOST@T

Page 198: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 198/199

20120101D ?FGFH BI?FH JD CDGBIL 15.80 12020100101E GD;IL FLMGD=D KFN ODLMI 10.90 100

20110101C LDMDPI BBFFBBL JILF 14.60 200

20100101= IMFGI ;IMFHD DBFQD=FG 13.70 190

20130101F ;IRD CDDD CDGBIL DGMGI 19.90 200

40 ar.

Lbortorio N° 13

PROGRAMACION DIGITAL - CB412-I CICLO 2014-2 1--

Page 199: Laboratorios CB412 2014-2.pptx

7/21/2019 Laboratorios CB412 2014-2.pptx

http://slidepdf.com/reader/full/laboratorios-cb412-2014-2pptx 199/199