Least Common Multiple Finder

By BlueThen on Oct 18, 2008

Finds the Least Common Multiple for any two numbers given.

#include <iostream>
using namespace std;
int main ()
{
 loop:
 int emr, n1, n2, t, n11, n22, q;
 cout << "Please enter the First Number ";
 cin >> n1;
 cout << "Please enter the Second Number ";
 cin >> n2;
 if (n1 < n2)
 {
 t = n1;
 n1 = n2;
 n2 = t;
 }
 n11 = n1;
 n22 = n2;
 while (n22 != n11)
 {
 if (n11 > n22)
   {
   n22 = n22 + n2;
   goto hai;
   }
 if (n11 < n22) 
   {
   n11 = n11 + n1;
   goto hai;
   }
 hai:
 emr++;
}
 cout << "The common factor is " << n11 << ".\n";
 cout << "Enter 0 to end the program, ";
  cout << "and 1 to start again: ";
  cin >> q;
  if (q == 1)
  goto loop;
  else
  return 0;
}

Comments

Sign in to comment.
foshizzle   -  Oct 30, 2008

this could be optimized :P

 Respond  
BlueThen   -  Oct 20, 2008

My bad, Least Common Multiple.

Very old script.

 Respond  
guest598594   -  Oct 20, 2008

I found this site helpful Neptune: http://www.cplusplus.com/doc/tutorial/

And there's some video tuts here: http://xoax.net/comp/cpp/console/index.php

 Respond  
^Neptune   -  Oct 20, 2008

Wow, big interest in C++ recently. Where'd you guys learn it?

 Respond  
guest598594   -  Oct 19, 2008

I'm kind of confused, this is GCF right?

Because I put in 27 and 9 and it's saying the common factor is 27, when it should be 9.

And when I put in 9 and 3 it gave me an error saying "emr" is being used without being initialized.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.