Sei sulla pagina 1di 7

1.

-
>> disp('DECIR SI UN NUMERO ES PAR O NO ')
n=input('ingrese el valor del numero : ');
if n>0
if (mod(n,2)==0)
fprintf('\n el numero es par \n %2.f')
else
fprintf('\t el numero es impar \n %2.f')
end
else (n<=0)
msgbox('el numero tiene que ser mayor que cero','alerta')
end

DECIR SI UN NUMERO ES PAR O NO


ingrese el valor del numero : 12

el numero es par
>>

2.-

>> a=input('ingrese el primer valor : ');

b=input('ingrese el segundo valor : ');

c=(a>0 & b>0);

if c==1;

s=a*b;

fprintf('\n el producto es : %2.f \n ',s)

elseif c==0;

s=a+b;

fprintf('\n el la suma es : %2.f \n ',s)

end

ingrese el primer valor : -5

ingrese el segundo valor : 6

el la suma es : 1

>>

3.-

>> global a
fprintf('\n el menor de los n #s es \n ')

n=input('ingrese el numero de valores a ingresar : ')

for k =1:n

a(k)=input('ingrese valores uno por uno : ');

end

for i=1:(n-1)

for j=1:(n-1)

if (a(j)>a(j+1));

k=a(j);

a(j)=a(j+1);

a(j+1)=k;

end;

end;

end;

fprintf('\n el numero menor es : %3.f \n ', a(1))

EL MENOR DE LOS N NUMEROS

ingrese el numero de valores a ingresar : 5

n=

ingrese valores : 1

ingrese valores : 2

ingrese valores : 5

ingrese valores : 1

ingrese valores : 9
el numero menor es : 1

>>

4.-
global fun
fprintf('\n PROGRAMA QUE HALLA RAICES DE UN FUNCION CUADRATICA \n ')
fun=input('ingrese funcion cuadratica :','s');
solve(fun)

5.-
fprintf('\n PRO0GRAMA QUE DETERMINA SI SE PUEDE OBTENER UN TRIANGULO CON
3 LONGITUDES \n');
a=input('ingresar valor de la primera longitud : ');
b=input('ingresar valor de la segunda longitud : ');
c=input('ingresar valor de la tercera longitud : ');
s=((b-c<a)&(a<b+c)&(a-c<b)&(b<a+c)&(b-a<c)&(c<b+a));
if s==1
fprintf('si se puede formar un triangulo');
r=((a==b)&(a==c)&(c==b));
if r==1
fprintf('el triangulo es equilatero');
elseif r==0;
fprintf('el triangulo es escaleno');
elseif (((a==b)&(b~=c))|((a==c)&(c~=b))|((b==c)&(c~=a)));
fprintf('el triangulo es isoseles');
end
elseif s==0
fprintf('no se puede determinar un triangulo con las longitudes')
end

PRO0GRAMA QUE DETERMINA SI SE PUEDE OBTENER UN TRIANGULO CON 3


LONGITUDES

ingresar valor de la primera longitud : 4

ingresar valor de la segunda longitud : 2

ingresar valor de la tercera longitud : 3

si se puede formar un triangulo, el triangulo es escaleno>>

6.-
global func
fprintf('\n EVALUAR Y GRAFICAR LA SIGUIENTE FUNCION \n\n');
fprintf(' x^2+1 si x<=3\n');
fprintf(' f(x) x^2+1 +3*3 si 0<x<=3\n');
fprintf(' x+1 si x>3\n');
a=input('ingrese el numero a evaluar : ');
syms x
if a<=0
func=x.^2+1
elseif (0<a)&(a<3)
func=x.^2+3*x+2
elseif a>=3
func=x+1
end
x=linspace(-10,10,900);
y=(x.^2+1).*(x<=0)+(x.^2+3*x+2).*((0<x)&(x<3))+(x+1).*(x>=3);
plot(x,y);title('grafica de la funcion f(x)')
x=a;
s=eval(func)
fprintf('el valor del numero evaluado es : %2.f \n ',s)

PROGRAMA QUE EVALUA Y GRAFICA DE LA SIGUIENTE FUNCION

x^2+1 si x<=3

f(x) x^2+1 +3*3 si 0<x<=3

x+1 si x>3

ingrese el numero a evaluar : 2

func =

x^2+3*x+2

s=

12el valor del numero evaluado es : 12

>>
7.-
fprintf('\n PROGRAMA QUE EVALUA EL VALOR DE LA SIGUIENTE FUNCION \n');

fprintf(' 2a+b si a^2-b^2<0 \n');

fprintf(' f(a,b) a^2-2b si a^2-b^2=0 \n');


fprintf(' a+b si a^2-b^2>0 \n');
a=input('ingrese el valor de a : ');
b=input('ingrese el valor de b : ');
s=(a.^2-b.^2);
if s<0;
f(x)=2*a+b;
elseif s==0;
f(x)=a.^2-2*b;
elseif s>0;
f(x)=a+b;
end
h=f(x);
fprintf('\n f(x)= %2.f \n ',h)

PROGRAMA QUE EVALUA EL VALOR DE LA SIGUIENTE FUNCION


2a+b si a^2-b^2<0

f(a,b) a^2-2b si a^2-b^2=0

a+b si a^2-b^2>0

ingrese el valor de a : 2

ingrese el valor de b : 3

f(x)= 7 >>
8.-
global a
fprintf('\n NUMERO INTERMEDIO DE LOS 3 NUMEROS A INGRESAR\n ')
for k =1:3
a(k)=input('ingrese valor : ');
end
for i=1:(2)
for j=1:(2)
if (a(j)>a(j+1));
k=a(j);
a(j)=a(j+1);
a(j+1)=k;
end;
end;
end;
fprintf('\n el numero menor es : %3.f \n ', a(2))

NUMERO INTERMEDIO DE LOS 3 NUMEROS A INGRESAR

ingrese valor : 2

ingrese valor : 5

ingrese valor : 15

el numero menor es : 5

>>

9.-

10.-
fprintf('\n EL ESTADO EN EL QUE SE ENCUENTRA UN ALUMNO DE ACUERDO A 3
NOTAS DEL SEMSTRE\n');
t=input('ingrese la nota de trabajos : ');
m=input('ingrese la nota de medio ciclo : ');
f=input('ingrese la nota de final de ciclo : ');
s=t/5+m*2/5+f*2/5 ;
if ((s>6)&(s<=10));
fprintf('\n su estado es MALO \n ');
elseif ((s>=11)&(s<=15));
fprintf('\n su estado es REGULAR \n ');
elseif ((s>=16)&(s<=20));
fprintf('\n su estado es BUENO \n ');
elseif (s<=6)
fprintf('\n su estado es PEJE \n ');
end

EL ESTADO EN EL QUE SE ENCUENTRA UN ALUMNO DE ACUERDO A 3 NOTAS


DEL SEMESTRE

ingrese la nota de trabajos : 12

ingrese la nota de medio ciclo : 20

ingrese la nota de final de ciclo : 19

su estado es BUENO

>>

Potrebbero piacerti anche