Question: how can i write a c programme that calls a function Euclid's algorithm? The Greatest Common Divisor (GCD) of two positive integers is the largest integer which can be divided evenly into both integers.\nProblem 1: Given two integers A and B (assume that A > B) write a C program that calls a function called primitiveGCD( A,B) to calculate the GCD of two positive integers. This function uses a simple algorithm based on successive test of all numbers less than or equal to B, in order to find the greatest common divisor.\nThe pseudo-algorithm for implementing the function is as follows:\n1. Require that A ≥ 0 and B ≥ 0\n2. If A < B swap A and B\n3. Set g = B\n4. While g does not simultaneously divide A and B let g=g-1\n5. Return g\nProblem 2: Similar to the problem 1 chapter 5 page 338 of the textbook.\nEuclide’s algorithm for calculating the GCD of two positive integers is based on the following observation:\nGiven two nonnegative integers A and B where (A > B), then the greatest common divisor of A and B is also the common divisor of A%B and B.

Answer: int primitiveGCD(int A, int B){\n  int g;\n  if (A < 0 || B < 0 ) return -1; /*error*/\n  g = B;\n  if (A < B){B = A; A = g; g = B;}\n  /* if g is not a factor of either it will return true value and it will continue looping */\n  while(A%g || B%g)g--;\n\n  return g;\n}\n\nYou can at least write the program. Cheating doesn't help you learn.
This question from the Yahoo Q&A forum is categorized in the topic: Computers & Internet