Matlab-Numeros Primos

Páginas: 2 (309 palabras) Publicado: 13 de noviembre de 2012
PROGRAMA 1 PARA TERMINADOS EN 3
clear
clc
S=0;
C=0;
A= input('Ingrese el valor inicial del rango: ');
B= input('Ingrese el valor final del rango: ');
for N=A:B
% se conoce si Nes un número primo o no
J=3;
for M=2:N-1
if (N/M)==fix(N/M)
J=9;
end
end
if J==3
if((N/10)-fix(N/10))==0.3 || ((N/100)-fix(N/100))==0.3 ||((N/1000)-fix(N/1000))==0.3 ||((N/10000)-fix(N/10000))==0.3
N
S=S+N;
C=C+1;
endend
end
S
C

PROGRAMA 2 PARA TERMINADOS EN 7
clear
clc
S=0;
C=0;
A= input('Ingrese el valor inicial del rango: ');
B= input('Ingrese el valorfinal del rango: ');
for N=A:B
% se conoce si N es un número primo o no
J=3;
for M=2:N-1
if (N/M)==fix(N/M)
J=9;
end
endif J==3
if fix(N/10))-((N/10)== 0.3 || fix(N/100)) -((N/100) ==0.3 ||( fix(N/1000)) -(N/1000) ==0.3 || fix(N/10000)) -((N/10000) ==0.3
NS=S+N;
C=C+1;
end
end
end
S
C


PROGRAMA 3 PARA TERMINADOS EN 9
clear
clc
S=0;
C=0;
A=input('Ingrese el valor inicial del rango: ');
B= input('Ingrese el valor final del rango: ');
for N=A:B
% se conoce si N es un número primo o no
J=3;
for M=2:N-1
if(N/M)==fix(N/M)
J=9;
end
end
if J==3
if fix(N/10))-((N/10)== 0.1 || fix(N/100)) -((N/100) ==0.1 ||( fix(N/1000)) -(N/1000) ==0.1|| fix(N/10000)) -((N/10000) ==0.1
N
S=S+N;
C=C+1;
end
end
end
S
C
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Numeros primos
  • NUMERO PRIMOS
  • numeros primos
  • Los numeros primos
  • numeros primos
  • numeros primos
  • Numeros primos
  • numeros primos

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS