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 ~ $

1 comment:

  1. Thanks a lot for the post. It has helped me get some nice ideas. I hope I will see some really good result soon.

    Catninja.org
    Wormate-io.com

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...