Code For Alls..!

get the code!!

Thursday 7 September 2017

HCF (GCD) of long values

                                    HCF (GCD) of long values
The program must accept two long values X, Y and print their HCF (GCD).
Input Format:
The first line contains X and Y separated by a space.
Output Format:
The first line contains the HCF (GCD) of X and Y.
Boundary Conditions:
1 <=  X, Y <= 999999999999
Example Input/Output 1:
Input:
20 30
Output:
10
Example Input/Output 2:
Input:
999999999999 151515151515
Output:
30303030303
c program:
#include<stdio.h>
#include <stdlib.h>

int main()
{
long int a,b;
scanf("%ld%ld",&a,&b);
while(a!=b)
{
    if(a>b)
    a=a-b;
    else
    b=b-a;
}
printf("%ld",a);

}

No comments:

Post a Comment