answersLogoWhite

0

Use the following function:

int gcd (int a, int b) {

while (b != 0) {

a %= b;

a ^= b ^= a ^= b;

}

return a;

}

Note that a ^= b ^= a ^= b is an efficient method of swapping two values.

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

What is recursive algorithm?

Algorithm can be defined as an interpretable, finite set of instructions for dealing with contigencies and accompanying task that has recognizable end-points for given inputs. It is a tool for solving a well computational problem. A recursive algorithm is one which calls itself.


What is a recursive function?

A recursive function is one that calls upon itself until a given result in the original call is met. Take a look at this example. Program Recursion; Uses crt; Var number:longint; Function Factorial(number:longint):longint; Begin if number > 0 then factorial:=number*factorial(number-1) else factorial:=1; End; Begin clrscr; readln(number); writeln(factorial(number)); readln; End. Note how the function factorial calls itself.


Write a C program to extract a given word from a file?

program to extract a given word from a file


How do you choose between recursion and iteration?

Some problems cry out for recursion. For example, an algorithm might be defined recursively (e.g. the Fibonacci function). When an algorithm is given with a recursive definition, the recursive implementation is straight-forward. However, it can be shown that all recursive implementations have an iterative functional equivalent, and vice versa. Systems requiring maximum processing speed, or requiring execution within very limited resources (for example, limited stack depth), are generally better implemented using iteration.


How does Static RAM function?

Basically, it has two major functions: store data to a given address and retrieve data from a given address.

Related Questions

Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling


What is recursive algorithm?

Algorithm can be defined as an interpretable, finite set of instructions for dealing with contigencies and accompanying task that has recognizable end-points for given inputs. It is a tool for solving a well computational problem. A recursive algorithm is one which calls itself.


What is the sum of the integers in the square grid that are equal to the given integer value?

To find the sum of integers in a square grid that match a given value, add up all the matching integers in the grid.


Will the explicit formula find the same answer when using the recursive formula?

It is often possible to find an explicit formula that gives the same answer as a given recursive formula - and vice versa. I don't think you can always find an explicit formula that gives the same answer.


What is the recursive approach for finding the longest increasing subsequence in a given sequence?

The recursive approach for finding the longest increasing subsequence in a given sequence involves breaking down the problem into smaller subproblems and solving them recursively. This method involves comparing each element in the sequence with the previous elements to determine the longest increasing subsequence.


What is a recursive function?

A recursive function is one that calls upon itself until a given result in the original call is met. Take a look at this example. Program Recursion; Uses crt; Var number:longint; Function Factorial(number:longint):longint; Begin if number > 0 then factorial:=number*factorial(number-1) else factorial:=1; End; Begin clrscr; readln(number); writeln(factorial(number)); readln; End. Note how the function factorial calls itself.


How write a java program to generate random numbers in between 0-100 and print only the odd numbers?

Use a pseudo-random number generator to produce random integers. To determine if a given integer is odd or even, use the following functions: bool is_odd (int x) { return x%2; } bool is_even (int x) { return !is_odd (x); }


The sum of two consecutive integers is -6943 what are the integers?

Two consecutive integers will be 0.5 more and 0.5 less than the quotient of their sum divided by 2. The given sum of the two consecutive integers divided by 2 is -3471.5, so the two consecutive integers are -3472 and -3471.


Which set is closed under the given operation 1 integers under division 2 negative integers under subtraction 3 odd integers under multiplication?

1 No. 2 No. 3 Yes.


How many integers in 25 to 41?

17 including the two numbers given.


What is the sum of the all given integers between 9 and 27?

Sum = 306.


How do you find the integers when given their ratio?

You cannot. If the ratio gives x and y as the integers then so also are 2x and 2y, or 3x and 3y and so on.