L.C.M and G.C.D of two numbers using function


How to write C Program to calculate L.C.M and G.C.D of two numbers using function

#include<stdio.h>
void gcd(int,int);
void lcm(int,int);

int main()
{
    int a,b;

    printf("Enter two numbers: \t");
    scanf("%d %d",&a,&b);

    lcm(a,b);
    gcd(a,b);


    return 0;
}

//function to calculate l.c.m
void lcm(int a,int b)
{
    int m,n;

    m=a;
    n=b;

    while(m!=n)
    {
        if(m<n)
            m=m+a;
        else
            n=n+b;
    }

    printf("\nL.C.M of %d  &  %d is %d",a,b,m);
}

//function to calculate g.c.d
void gcd(int a,int b)
{
    int m,n;

    m=a;
    n=b;

    while(m!=n)
    {
        if(m>n)
            m=m-n;
        else
            n=n-m;
    }

    printf("\nG.C.D of %d  &  %d is %d",a,b,m);
}




Comments

Popular posts from this blog