GCD Programming Computer Science by Dietrich_1 … console window it just runs and nothing happens: public class GCD { public static void main(String[]args) { int n = 5…small ; larger = small ; small = larger ; } System.out.print("The GCD of " + n + "and" + d + "is … GCD Help. Programming Software Development by Jake1905 … result cout << endl ; cout << "The GCD is: " << y << endl ; return (0… Re: GCD Help. Programming Software Development by ixmike88 what's the problem? i'm guessing it's compiler errors since your gcd equation looks fine and i see some syntax errors on lines 25 and 37, your if/while statements shouldn't have semicolons here's some examples if needed: [url]http://www.cplusplus.com/doc/tutorial/control/[/url] GCD Nonrecursive Beginner Programming Software Development by ronak127 …import java.util.Scanner; public class GCD { public static int GCD; public static int div; public static…num2 = remainder; } num2 = GCD; System.out.println("The GCD is: " + GCD); } while (GCD >= 0); }//Ending bracket of… Re: GCD function Programming Software Development by COKEDUDE … I fixed it. I forgot to add the errors. gcd.c: In function 'gcd': gcd.c:13: warning: 'return' with a value, in… function returning void gcd.c:24: warning: 'return' with a value, in function …returning void gcd.c: In function 'main': gcd.c:35: error: 'x' undeclared (first use … GCD with array Programming Software Development by algrandjean1 I am having some trouble with a gcd program that I have created. My problem …THe format for the output is: Num1 Num2 GCD Num1 Num2 GCD for how ever many sets the user specifies. …int num2){ while(num2 >0){ int gcd = num1 % num2; num1 = num2; num2 = gcd; } return num1; } public static void main… Re: GCD Nonrecursive Beginner Programming Software Development by mrnutty … = num1 / num2; remainder = num1 % num2; num1 = num2; num2 = remainder; } num2 = GCD;[/CODE][/QUOTE] Since remainder is 0, this won't get… executed and num2 is set to GCD which you haven't defined, so it will be 0… Re: GCD with array Programming Software Development by algrandjean1 … store the values from each iteration of sets (num1, num2, gcd) and print them all out at the same time after… the second number: 10 Number 1: 5 Number 2: 10 GCD: 5 Please enter the first number: 9 Please enter the… GCD brute force Programming Software Development by plike922 I am trying to create a program that finds the GCD of two numbers using the brute force... So far i … "simpio.h" #include "strlib.h" int GCD(int x, int y) { int g; g = x; while (x… = "); scanf("%d",&n2); printf("The GCD of %d and %d is %d",n1,n2… Re: GCD brute force Programming Software Development by Major Major [QUOTE] [CODE] printf("The GCD of %d and %d is %d",n1,n2,GCD(g)); [/CODE][/QUOTE] Try this instead [CODE] printf("The GCD of %d and %d is %d",n1,n2,GCD(n1,n2)); [/CODE] Re: GCD Algo. Help Programming Software Development by Narue … <iostream> using namespace std; int gcd ( int m, int n ) { return n ? gcd ( n, m % n ) : m; } int main()… num; cin.get(); cin>> den; int div = gcd ( num, den ); cout<<"The reduced fraction is…div <<endl; } [/code] Though you should take that GCD function with a grain of salt. It's quick and… Re: GCD Algo. Help Programming Software Development by dontcare … <iostream> using namespace std; int gcd ( int m, int n ) { return n ? gcd ( n, m % n ) : m; } int main()… num; cin.get(); cin>> den; int div = gcd ( num, den ); cout<<"The reduced fraction is…div <<endl; } [/code] Though you should take that GCD function with a grain of salt. It's quick and… Re: GCD brute force Programming Software Development by Aia In main: [CODE]int result; result = GCD( n1, n2); printf("result = %d\n", result);[/CODE] GCD Algo. Help Programming Software Development by dontcare I need help using the GCD Algo. in my program, I can't figure out to …use the algo in my program. The algo: int gcd(int a, int b){ assert(b != 0); int rem = a… Re: GCD Algo. Help Programming Software Development by dontcare … fractions using the following but I have to use the gcd algo. and i have to use it to reduce the… Re: GCD Algo. Help Programming Software Development by dontcare sorry, with code tags now: [code] int gcd(int a, int b){ assert(b != 0); int rem = a % … Re: gcd problem Programming Software Development by JoBe … Algorithm of Euclides? Example of getting the greatest common devider gcd(1147, 851) Steps: 1) 1147 = 1x851 + 296 2) 851 = 2x296… = 1x259 + 37 4) 259 = 7x37 Rest equals 0. Then the gcd equals 37. If you can translate this into C++ code… Re: gcd problem Programming Software Development by mdbrock7 … get an answer of zero which is obviously not the gcd. I have spent hours trying to adjust it but I…; n = t; } m = m - n; } cout << "the gcd of" << endl; cout << firstNum; cout… gcd problem Programming Software Development by mdbrock7 …; n = t; } m = n - m; } cout << "the gcd of" << endl; cout << firstNum; cout… Re: gcd problem Programming Software Development by Narue The traditional (if inefficient) algorithm is: [code] # Pseudocode gcd ( m, n ) begin while m != n do if m > n m := m - n else n := n - m loop return m end [/code] Re: gcd problem Programming Software Development by mdbrock7 … n = n - m; } return m; cout << "the gcd of" << endl; cout << firstNum; cout… Re: gcd problem Programming Software Development by Narue … - n; else n = n - m; } cout << "the gcd of " << firstNum << " and "… GCD function Programming Software Development by COKEDUDE … compile this code and how to fix it? [CODE]void gcd(int x, int y) { if (x > y) { int c… Re: GCD Programming Computer Science by tinstaafl Not sure what this loop: while(small !=0) { int remainder = larger % small ; larger = small ; small = larger ; } is supposed to do, but `larger` and `small` never change, therefore `small` will never get to 0. All you're doing is swapping the values over and over … Re: GCD Help. Programming Software Development by daviddoria I would do two things to start debugging. First, get rid of the user input and hardcode some values. Once it works with the hardcoded values, you can put the user input back in. Second, write out the steps of the algorithm for the same values you have hard coded. Use cout statments (or better, a debugger) at every place you can to track the … Re: Euclid gcd Programming Software Development by jimJohnson …lt; "." << endl; } //change int gcd (int firstRandomNumber, int secondRandomNumber) { //change //if (x==0)…lt; firstRandomNumber << secondRandomNumber; int x = gcd(secondRandomNumber, firstRandomNumber); //gcd(firstRandomNumber, secondRandomNumber); //changed //cout << … Euclid gcd Programming Software Development by jimJohnson …secondRandomNumber==0) { //change return firstRandomNumber; } else { return gcd (secondRandomNumber, firstRandomNumber % secondRandomNumber); } } //CREATE AN UNSIGNED …printf ("Call Euclid\n"); //changed gcd(firstRandomNumber, secondRandomNumber); //changed //OUTPUT OF EUCLAID… Help with gcd and fractions Programming Software Development by jdm …regular: ;continue program call gcd ;Find the gcd of the product of the…;Divide the denominator by the gcd value call writeint ;Display reduce… Fraction class calling GCD in add method and normalizing a fraction Programming Software Development by TheLittleEngine … member functions void Rational::reduce(Rational){ int tnum, tden, temp, gcd; tnum = labs(numerator); // use non-negative copies tden = labs(… is greatest common divisor numerator = numerator / gcd; // divide both num and den by gcd denominator = denominator / gcd; // to reduce frac to lowest terms… Re: Euclid gcd Programming Software Development by nezachem … firstRandomNumber, int secondRandomNumber) { if (secondRandomNumber==0) { return firstRandomNumber; } else { return gcd (secondRandomNumber, firstRandomNumber % secondRandomNumber); } } int main() { printf("%d\n"…