The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+7 votes

Consider the following C program

    int x, y, m, n;
    scanf("%d %d", &x, &y);
    /* Assume x>0 and y>0*/
    m = x; n = y;
    while(m != n)
            if (m > n)
                m = m-n;
                n = n-m;
    printf("%d", n);

The program computes

  1. $x+y$ using repeated subtraction

  2. $x \mod y$ using repeated subtraction

  3. the greatest common divisor of $x$ and $y$

  4. the least common multiple of $x$ and $y$

asked in Algorithms by Veteran (69k points) | 811 views

2 Answers

+9 votes
Best answer

It is a simple algorithm of gcd

here while loop executes until $m==n$

take any two number as $m$,$n$ and compute it , get the answer

Ans will be (C)

answered by Veteran (81.5k points)
edited by
+5 votes
c) euclidean algorithm
answered by Active (1k points)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

33,704 questions
40,252 answers
38,859 users