Solucion 2do Parcial

Anuncio
Solucion 2do Parcial
Computación 1
Facultad de Ingenieria - UdelaR
1
Ejercicio 1
a) 5555
b) 00100
c) 24,0
d) 0 10000000 11000000000000000000000
e) De menor a mayor:
1 10000011 10000000000000000000000 = -24.0
0 10000000 10000000000000000000000 = 3.0
0 10001000 00000000000000000000000 = 512.0
1
2
Ejercicio 2
a)
1
2
3
4
5
6
function w = invertirvector (v)
lv = length (v) ;
w = zeros (1 , lv ) ;
f o r pos = 1 : l v
w( pos ) = v ( l v −pos +1) ;
end
b)
1
2
3
4
5
6
7
function w = crearCapicua (v)
lv = length (v) ;
i f l v == 0
w = [];
else
w = [ v (1) crearCapicua (v ( 2 : lv ) ) v (1) ] ;
end
c)
1
2
3
4
5
6
7
8
9
f u n c t i o n r e s = esCapicua ( v )
lv = length (v) ;
i f l v==0 | l v==1
res = 1;
e l s e i f v ( 1 ) ˜=v ( l v )
r e s =0;
else
r e s= e s C a p i c u a ( v ( 2 : l v −1) ) ;
end
2
3
Ejercicio 3
a)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
f u n c t i o n w=i n t e r s e c c i o n ( u , v )
nu = l e n g t h ( u ) ;
nv = l e n g t h ( v ) ;
i = 1;
j = 1;
w = [];
w h i l e i <=nu & j<=nv
i f u ( i )==v ( j )
w = [ w, u ( i ) ] ;
i = i +1;
j = j +1;
e l s e i f u ( i )>v ( j )
j = j +1;
else
i = i +1;
end
end
b)
1
2
3
4
5
6
7
8
9
10
11
12
f u n c t i o n z=d i f e r e n c i a ( u , v )
nu = l e n g t h ( u ) ;
nv = l e n g t h ( v ) ;
i f nu==0 | nv==0
z = u;
e l s e i f u ( 1 )==v ( 1 )
z = d i f e r e n c i a ( u ( 2 : nu ) , v ( 2 : nv ) ) ;
e l s e i f u ( 1 )>v ( 1 )
z = d i f e r e n c i a ( u , v ( 2 : nv ) ) ;
else
z = [ u ( 1 ) d i f e r e n c i a ( u ( 2 : nu ) , v ) ] ;
end
3
4
Ejercicio 4
a)
1
2
3
4
5
6
7
8
9
10
11
f u n c t i o n [ maxPar , minImpar ]=MaxMinI (An , Af , Ac )
lA = l e n g t h (An) ;
maxPar = 0 ;
minImpar = 0 ;
f o r i = 1 : lA
i f mod( Af ( i ) + Ac ( i ) , 2 )==0 & maxPar<An( i )
maxPar = An( i ) ;
e l s e i f mod( Af ( i ) + Ac ( i ) , 2 )==1 & minImpar>An( i )
minImpar = An( i ) ;
end
end
b)
1
2
3
4
5
6
7
8
9
10
11
12
13
f u n c t i o n [ maxPar , minImpar ]=MaxMinR(An , Af , Ac )
lA = l e n g t h (An) ;
i f lA==0
maxPar = 0 ;
minImpar = 0 ;
else
[ maxPar , minImpar ] = MaxMinR(An ( 2 : n ) , Af ( 2 : n ) , Ac ( 2 : n ) ) ;
i f mod( Af ( 1 ) + Ac ( 1 ) , 2 )==0 & maxPar<An ( 1 )
maxPar = An ( 1 ) ;
e l s e i f mod( Af ( 1 ) + Ac ( 1 ) , 2 )==1 & minImpar>An ( 1 )
minImpar = An ( 1 ) ;
end
end
4
Descargar