Computer Sciences > GATE 2025 SET-2 > C Programming

Correct : 21
The correct answer is 21.
The given C code repeatedly subtracts the smaller number from the larger one until both values become equal.
This is an implementation of the Euclidean algorithm (using subtraction) to compute the GCD (Greatest Common Divisor) of two numbers.
Initially, x = 126 and y = 105.
At each step:
If x > y, then x = x − y
Else, y = y − x
This process continues until x = y.
The sequence eventually converges to 21, which is the GCD of 126 and 105.
Finally, the program prints the value of x, which is 21.
Similar Questions
Consider the following two functions
void fun1(int n){
if(n == 0) return;
printf(“%d”, n);
fun2(n-2);
&...
Consider the C functions foo and bar given below:
int foo(int val)
{
int x = 0;
while (val > 0)
{
&nbs...
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
int a[3][3][3] =
{{...
Total Unique Visitors
Loading......