Find GCD(greatest common divisor)& LCM (least common multiple) of Two Numbers - C Program

Program:
#include<stdio.h>
//#include<conio.h>
//void
main()
{
    int r,a,b,l,m,n;
    printf("Enter the numbers:\n");
    scanf("\n%d%d",&m,&n);
    a=m;
    b=n;
    while(r!=0)
    {
        r=m%n;
        m=n;
        n=r;
    }
    printf("G C D: %d\n",m);
    l=a*b/m;
    printf("L C M: %d\n",l);
//       getch();
}

Output:
nn@linuxmint ~ $ gcc c7.c
nn@linuxmint ~ $ ./a.out
Enter the numbers:
18
12
G C D: 6
L C M: 36
nn@linuxmint ~ $

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...