// common.c : µÎ ¼ö(num1,num2)ÀÇ ÃÖ´ë°ø¾à¼ö¿Í ÃÖ¼Ò°ø¹è¼ö¸¦ ±¸ÇÑ´Ù. // µÎ ¼ö Áß¿¡¼ Å« ¼ö¸¦ ÀÛÀº ¼ö·Î ³ª´©¾î¼ // ³ª´©¾î ¶³¾îÁö¸é ÀÛÀº ¼ö°¡ °ð ÃÖ´ë°ø¾à¼ö(gcm)°¡ µÈ´Ù. // ³ª¸ÓÁö°¡ ÀÖ´Â °æ¿ì¿¡´Â ´Ù½Ã ÀÛÀº ¼ö¸¦ Å« ¼ö·Î Çϰí // ³ª¸ÓÁö¸¦ ÀÛÀº ¼ö·Î ÇØ¼ ³ª¸ÓÁö°¡ 0ÀÌ µÉ ¶§±îÁö À§ÀÇ °úÁ¤À» ¹Ýº¹ÇÑ´Ù. // ÃÖ¼Ò°ø¹è¼ö(lcm)´Â µÎ ¼ö¸¦ °öÇÑ ¼ö¸¦ ÃÖ´ë°ø¾à¼ö·Î ³ª´©¾îÁÖ¸é µÈ´Ù. #include <stdio.h> void main() { int num1, num2; int temp1, temp2, r; int gcm, lcm; printf( "Insert the 1st number : "); scanf( "%d", &num1); printf( "Insert the 2nd number : "); scanf( "%d", &num2); r=1; if( num1 > num2) { temp1 = num1; temp2 = num2; } else { temp1 = num2; temp2 = num1; } while( r != 0) { r = temp1 % temp2; if( r == 0) { gcm = temp2; break; } else { temp1 = temp2; temp2 = r; } } lcm = ( num1 * num2) / gcm; printf( "G.C.M : %d \n", gcm); printf( "L.C.M : %d \n", lcm); } |