Академический Документы
Профессиональный Документы
Культура Документы
2. SOLUCION:
For:
clear all;
clc;
n=input('ingrese un numero');
s=0;
for c=1:1:n-1
if mod(n,c)==0
fprintf('%d',c)
s=s+c;
end
end
if n~=s
fprintf('numero no es divisor'):
else
fprintf('numero es divisor');
end
while:
clear all;
clc;
n=input('ingrese un numero');
s=0;
c=1;
while c<=n
fprintf('%d\n',c)
s=s+c;
c=1/c*c;
end
fprintf('la suma es %d',s);
3. SOLUCION:
FOR
clear all
clc;
n=input('ingrese un numero');
s=0;
for c=1:1:n
if mod(n,c)==0
s=s+1;
s=sqrt(s);
end
end
if s~=2
fprintf('numero no es primo ');
else
fprintf('numero es primo ');
end
WHILE
clear all
clc;
n=input('ingrese un numero');
s=0;
fprintf('%d',s);
while c<=n-1
if mod(n,c)==0
s=s+1;
s=sqrt(s);
fprintf('%d',s);
end
end
if s~=2
fprintf('numero no es primo ');
else
fprintf('numero es primo ');
end
4. SOLUCION :
5. SOLUCION:
clear all;
clc;
n=input('ingrese un numero');
s=0;
c=1;
while c<=n
s=s+c;
c=c+1;
end
fprintf('la suma es %d',s);
6. SOLUCION:
clc;
n=input('ingrese un n');
s=0;
for c<=n;
error
if mod(n,c)==0
s=s+1;
end
c=c+1;
no debe ir
end
if s~=2
fprintf('el numero no es primo, tiene % divisores',s);
else
disp('el numero es primo tiene solo % divisores', s);
end