Sei sulla pagina 1di 21

FACULTAD DE INGENIERÍA

ESCUELA PROFESIONAL DE INGENIERÍA DE SISTEMAS

PRACTICA 12.1: “FUNCIONES”

AUTOR(ES):

Espinoza Loarte, María Claudia


Garay Sigil, Herbert Joseph Verde
Laguna Jaramillo, Enoc
Valladolid Hernández, Juan Pablo
Barrientos Fernandez Aldair Josimar
Escalante Neciosup Abel Joseph

Adrian José Rivas Tovar

ASESOR(A)(ES):
Ingeniero Berrocal Navarro, Richard Leonardo

LIMA — PERÚ

(2021)
Trazo:

1. MCD DE 2 NUMEROS ENTEROS: MCD(16,12)=4

Divisores 12= 1,2,3,4,6,12

Divisores 16= 1,2,4,8,16

public static int nummaxdiv(int num1, int num2) {

int resultado = 0;

ingreso // num1 = 16

ingreso // num2 = 12

(a) 16 = Math.max(16, 12);

(b) 12 = Math.min(16, 12);

do {

resultado (0) = 12 (b);

4(b) = 16(a) % 12(b);

a (12)= resultado(12);

} while (b (4) != 0);

Resultado (12) = 4 (b);

4 = 12(a) % 4(b);

a (12)= resultado(4);

} while (b (0) != 0);

"el MCD es: " + resultado (4));

return resultado;

2. DIVISORES DE UN NUMERO ENTERO: 4 = 1,2,4

public static int reportarDivisores(int numero1) {

int contador = 0;

int residuo;

4= ("Diguite un numero: "));

for (int i = 1; i <= 4; i++) {

residuo (0) = 4 % i(1);

if (residuo == 0) {

contador++(1);

JOptionPane.showMessageDialog(null, i(1));

for (int 2 = 1; 2 <= 4; 2++) {

residuo (0) = 4 % i(2);

if (residuo == 0) {
contador++(1) (2);

for (int 3 = 1; 3 <= 4; 3++) {

residuo (1) = 4 % i(3);

if (residuo == 0) {

for (int 4 = 1; 4<= 4; 4++) {

residuo (0) = 4 % i(4);

if (residuo == 0) {

contador++(1) (2)(4)(;

JOptionPane.showMessageDialog(null, i(1)(2)(4));

JOptionPane.showMessageDialog(null, "la cantidad de sus divisores son: " + 3 );

return contador;

3. FACTORES PRIMO DE UN NUMERO ENTERO: 6=2x3

public static int FactoresPrimos(int nume1){

int factor=2;

nume1(6) = Diguite un numero:

for (factor = 2; factor<=6; factor(2)++) {

while (nume1(6)%factor(2)==0) {

JOptionPane.showMessageDialog(null,nume1 (6)+ "|" + factor(2));

for (factor = 2; factor<=6; factor(2)++) {

nume1(3)=nume1(6)/factor(2);

while (nume1(3)%factor(2)!=0) {

JOptionPane.showMessageDialog(null,nume1 (6)+ "|" + factor(2));

for (factor = 3; factor(3)<=3; factor(3)++) {

while (nume1(3)%factor(3)==0) {

JOptionPane.showMessageDialog(null,nume1 (6)+ "|" + factor(2));

JOptionPane.showMessageDialog(null,nume1 (6)+ "|" + factor(3));

return factor;

}
4. NUMERO PRIMO O NO: 7 = 1 y 7, tiene dos divisores si es primo

public static int numprimo(int numero) {

int primo = 0;

int c = 0;

numero (7)= Diguite un numero

for (int i = 1; i <= numero(7); i++) {

if (numero(7) % i == 0) {

c++(1);

for (int i = 2; 2 <= numero(7); 2++) {

if (numero(7) % 2 == 0) {

for (int i = 3; 3<= numero(7); 3++) {

if (numero(7) % 3 == 0) {

for (int i = 4; 4<= numero(7); 4++) {

if (numero(7) % 4 == 0) {

for (int i = 5; 5<= numero(7); 5++) {

if (numero(7) % 5 == 0) {

for (int i = 6; 6<= numero(6); 5++) {

if (numero(7) % 6 == 0) {

for (int i = 7; 7<= numero(7); 7++) {

if (numero(7) % i7== 0) {

c++(1)(7);

if (c == 2) {

JOptionPane.showMessageDialog(null, "Si es un numero primo"); (1)(7)

} else {

JOptionPane.showMessageDialog(null, "No es un numero primo");

return primo;

}
5. NUMEROS AMIGOS: 220 y 284

public static int numerosAmigos(int n1, int n2) {

int amigos = 0;

int sumaDivisoresUno = 0;

int sumaDivisoresDos = 0;

n1 = 220 ("Diguite primer numero: "));

n2 = 284 ("Diguite segundo numero: "));

for (int i = 1; i < n1(220); i++) {

if (n1 % i == 0) {

+ i(1 +2+4+ 5+ 10+ 11+ 20 +22+ 44+ 55+ 110)→son los divisores de 220

sumaDivisoresUno (284)= sumaDivisoresUno + i(1 +2+4+ 5+ 10+ 11+ 20 +22+ 44+ 55+ 110);

for (int i = 1; i < n2; i++) {

if (n2 % i == 0) {

+ i(1+ 2+ 4+ 71+ 141)→son los divisores de 284

sumaDivisoresDos (220) = sumaDivisoresDos + i(1+ 2+ 4+ 71+ 141);

if (sumaDivisoresDos (220) == n1 (220) && sumaDivisoresUno (284)== n2(284)) {

JOptionPane.showMessageDialog(null, "Son amigos"); (se cumple)

} else {

JOptionPane.showMessageDialog(null, "No son amigos");

return amigos;

Código:

package modulomenu;

import javax.swing.JOptionPane;

public class ModuloMenu {

public static void main(String[] args) {

int opcion = 0;
int numeroprimero = 0;

int mcd = 0;

int divisores = 0;

int numAmigos=0;

int factoresPrimoss=0;

while (opcion != 6) {

opcion = Integer.parseInt(JOptionPane.showInputDialog(

"MENU DE OPCIONES\n"

+ "************************\n"

+ "1. MCD DE 2 NUMEROS ENTEROS\n"

+ "2. DIVISORES DE UN NUMERO ENTERO\n"

+ "3. FACTORES PRIMO DE UN NUMERO ENTERO\n"

+ "4. NUMERO PRIMO O NO\n"

+ "5. NUMEROS AMIGOS\n"

+ "6. SALIR\n"

+ "Ingrese su opción:"));

switch (opcion) {

case 1:

int num1 = 0;

int num2 = 0;

mcd = nummaxdiv(num1, num2);

break;

case 2:

int numero1 = 0;

divisores = reportarDivisores(numero1);

break;

case 3:

int nume1=0;

factoresPrimoss=FactoresPrimos(nume1);

break;

case 4:

int numero = 0;

numeroprimero = numprimo(numero);

break;

case 5:

int n1=0;

int n2=0;
numAmigos=numerosAmigos(n1,n2);

break;

default:

if (opcion >= 7) {

JOptionPane.showMessageDialog(null, "INGRESO UN NÚMERO MAYOR A LA OPCIÓN,"

+ "POR FAVOR INGRESE UN VALOR VÁLIDO");

break;

public static int nummaxdiv(int num1, int num2) {

int resultado = 0;

num1 = Integer.parseInt(JOptionPane.showInputDialog("Diguite el primero número "));

num2 = Integer.parseInt(JOptionPane.showInputDialog("Diguite el segundo numero: "));

int a = Math.max(num1, num2);

int b = Math.min(num1, num2);

do {

resultado = b;

b = a % b;

a = resultado;

} while (b != 0);

JOptionPane.showMessageDialog(null, "el MCD es: " + resultado);

return resultado;

public static int reportarDivisores(int numero1) {

int contador = 0;

int residuo;

numero1 = Integer.parseInt(JOptionPane.showInputDialog("Diguite un numero: "));

for (int i = 1; i <= numero1; i++) {

residuo = numero1 % i;

if (residuo == 0) {
contador++;

JOptionPane.showMessageDialog(null, i);

JOptionPane.showMessageDialog(null, "la cantidad de sus divisores son: " + contador);

return contador;

public static int FactoresPrimos(int nume1){

int factor=2;

nume1 = Integer.parseInt(JOptionPane.showInputDialog("Diguite un numero: "));

for (factor = 2; factor<=nume1; factor++) {

while (nume1%factor==0) {

JOptionPane.showMessageDialog(null,nume1 + "|" + factor);

nume1=nume1/factor;

return factor;

public static int numprimo(int numero) {

int primo = 0;

int c = 0;

numero = Integer.parseInt(JOptionPane.showInputDialog("Diguite un numero: "));

for (int i = 1; i <= numero; i++) {

if (numero % i == 0) {

c++;

if (c == 2) {

JOptionPane.showMessageDialog(null, "Si es un numero primo");

} else {

JOptionPane.showMessageDialog(null, "No es un numero primo");

return primo;

}
public static int numerosAmigos(int n1, int n2) {

int amigos = 0;

int sumaDivisoresUno = 0;

int sumaDivisoresDos = 0;

n1 = Integer.parseInt(JOptionPane.showInputDialog("Diguite primer numero: "));

n2 = Integer.parseInt(JOptionPane.showInputDialog("Diguite segundo numero: "));

for (int i = 1; i < n1; i++) {

if (n1 % i == 0) {

sumaDivisoresUno = sumaDivisoresUno + i;

for (int i = 1; i < n2; i++) {

if (n2 % i == 0) {

sumaDivisoresDos = sumaDivisoresDos + i;

if (sumaDivisoresDos == n1 && sumaDivisoresUno == n2) {

JOptionPane.showMessageDialog(null, "Son amigos");

} else {

JOptionPane.showMessageDialog(null, "No son amigos");

return amigos;

Salida:

MCD DE 2 NUMEROS ENTEROS: MCD(16,12)=4


2. DIVISORES DE UN NUMERO ENTERO
FACTORES PRIMO DE UN NUMERO ENTERO: 6=2x3
4. NUMERO PRIMO O NO: 7 = 1 y 7, tiene dos divisores si es primo
5. NUMEROS AMIGOS: (220 y 284) son amigos

Potrebbero piacerti anche