Skip to content

Instantly share code, notes, and snippets.

@sanrodari
Forked from godie007/MinimoComunMultiplo
Created May 3, 2012 21:16
Show Gist options
  • Select an option

  • Save sanrodari/2589573 to your computer and use it in GitHub Desktop.

Select an option

Save sanrodari/2589573 to your computer and use it in GitHub Desktop.
Mire
package com.example;
import javax.swing.JOptionPane;
public class MinimoComunMultiplo {
public static void main(String[] args)
{
int a, b, t, t1, x;
a = Integer.parseInt(JOptionPane.showInputDialog("A"));
b = Integer.parseInt(JOptionPane.showInputDialog("B"));
t = 1; // constante inicializada para evitar la multiplicidad x cero
x = 2; // constante inicial
while (x <= a && x <= b)
{
while (a % x == 0 && b % x == 0)
{
a = a / x;
b = b / x;
t = t * x;
}
x++;
}
t1 = t;
t = t * a * b;
System.out.println("El mcm es :" + t);
System.out.println("El mcd es :" + t1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment