Recursion 6 : GCD and LCM of 2 Numbers

Description:

Write a program to compute GCD and LCM of 2 numbers using recursion. Input and Output Format: Input consists of 2 integers. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Test Case 1 Input (stdin) 14 16 Expected Output GCD=2 LCM=112 Test Case 2 Input (stdin) 30 40 Expected Output GCD=10 LCM=120

Program :

#include <stdio.h>

int main()

{

  int a, b, x, y,temp,GCD,LCM;

  scanf("%d",&x);

  scanf("%d",&y);

  a=x;

  b=y;

  while(b!=0)

  {

    temp=b;

    b=a%b;

    a=temp;

  }

  GCD=a;

  LCM=(x*y)/GCD;

  printf("GCD=%d\n",GCD);

  printf("LCM=%d\n",LCM);

  return 0;

}