A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d4/da0/gcd__iterative__euclidean_8cpp_source.html below:

TheAlgorithms/C++: math/gcd_iterative_euclidean.cpp Source File

Go to the documentation of this file. 15int gcd

(

int

num1,

int

num2) {

16 if

(num1 <= 0 | num2 <= 0) {

17 throw

std::domain_error(

"Euclidean algorithm domain is for ints > 0"

);

25 int

previous_remainder = 1;

29

previous_remainder = num2;

32

previous_remainder = num1;

35 while

((base_num % previous_remainder) != 0) {

36 int

old_base = base_num;

37

base_num = previous_remainder;

38

previous_remainder = old_base % previous_remainder;

41 return

previous_remainder;

48

std::cout <<

"gcd of 120,7 is "

<< (

gcd

(120, 7)) << std::endl;

50

std::cout <<

"gcd of -120,10 is "

<<

gcd

(-120, 10) << std::endl;

51

}

catch

(

const

std::domain_error &e) {

52

std::cout <<

"Error handling was successful"

<< std::endl;

54

std::cout <<

"gcd of 312,221 is "

<< (

gcd

(312, 221)) << std::endl;

55

std::cout <<

"gcd of 289,204 is "

<< (

gcd

(289, 204)) << std::endl;

int gcd(int num1, int num2)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4