Está en la página 1de 2

Nombre: Anthony Hurtado Bautista

Materia: Programación Aplicada Profesor: José Jaime Carriel

Año Lectivo: 2020-2020

Actividad 5: Algoritmo Validación Documento de Identificación

-Realizar un programa en Matlab que permita determinar si la cédula ingresada


es válida o inválida.

% Programa en MatLab que permite validar la cedula ecuatoriana.


clear
clc

cedula = input('Ingrese el documento de identificacion: ','s');


tam = length(cedula);
acumPar = 0;
acumImpar = 0;
sumPI = 0;

if (tam == 10)
prov = str2double(string(extractBetween(cedula,1,2)));
if (prov >= 1) && (prov <= 24)
digito = str2double(cedula(3));
if (digito < 6)
for x=1:9
res = mod(x,2);
if (res == 0)
acumPar = acumPar + (str2double(cedula(x))*1);
else
datoImpar = (str2double(cedula(x))*2);
if (datoImpar >= 10)
datoImpar = datoImpar -9;
end
acumImpar = acumImpar + datoImpar;
end
end
sumPI = acumImpar + acumPar;

if (sumPI >= 00) && ( sumPI <= 10)


DS = 10;
verificador = DS - sumPI;
end

if (sumPI >= 11) && ( sumPI <= 20)


DS = 20;
verificador = DS - sumPI;
end

if (sumPI >= 21) && ( sumPI <= 30)


DS = 30;
verificador = DS - sumPI;
end
if (sumPI >= 31) && ( sumPI <= 40)
DS = 40;
verificador = DS - sumPI;
end

if (sumPI >= 41) && ( sumPI <= 50)


DS = 50;
verificador = DS - sumPI;
end

if (sumPI >= 51) && ( sumPI <= 60)


DS = 60;
verificador = DS - sumPI;
end

if (sumPI >= 61) && ( sumPI <= 70)


DS = 70;
verificador = DS - sumPI;
end

if (sumPI >= 71) && ( sumPI <= 80)


DS = 80;
verificador = DS - sumPI;
end

if (sumPI >= 81) && ( sumPI <= 90)


DS = 90;
verificador = DS - sumPI;
end
if (sumPI >= 91) && ( sumPI <= 100)
DS = 100;
verificador = DS - sumPI;
end
digitoVer = str2double(cedula(10));
if (verificador == digitoVer)
disp('La cedula ingresada es Valida.')
else
disp('La cedula ingresada No es Valida.')
end
else
disp('El 3er digito de la cedula es incorrecto. Debe estar entre el 0 al 5')
end
else
disp('El codigo de provincia ingresado es incorrecto. Debe estar entre 01 al
24.')
end
else
disp('El numero de cedula ingresado no cumple con los 10 digitos de
identificacion.');
end

También podría gustarte