Heim  >  Artikel  >  Datenbank  >  最小公倍数

最小公倍数

WBOY
WBOYOriginal
2016-06-07 14:55:191526Durchsuche

求两个整数的最小公倍数 无 DECLARE @num1 BIGINT, @num2 BIGINT SET @num1=6 SET @num2=8DECLARE @result BIGINT DECLARE @max INT DECLARE @times INT IF @num1 = @num2 SET @max=@num2 ELSE SET @max=@num1 SET @times=@max WHILE( @times = @max ) BEGIN

求两个整数的最小公倍数
DECLARE @num1 BIGINT, 
        @num2 BIGINT 

SET @num1=6 
SET @num2=8

DECLARE @result BIGINT 
DECLARE @max INT 
DECLARE @times INT 

IF @num1 <= @num2 
  SET @max=@num2 
ELSE 
  SET @max=@num1 

SET @times=@max 

WHILE( @times >= @max ) 
  BEGIN 
      IF( @times%@num1 = 0 
          AND @times%@num2 = 0 ) 
        BEGIN 
            SET @result=@times 

            BREAK 
        END 

      SET @times=@times + 1 
  END 

SELECT @result
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn