gcd and lcd in c

Solutions on MaxInterview for gcd and lcd in c by the best coders in the world

showing results for - "gcd and lcd in c"
Bryden
24 Jan 2019
1#include <stdio.h>
2//here is a c programme which can find GCD and LCD
3
4int main(){
5
6    int n1,n2,num1,num2,rem,gcd,lcm;
7
8    printf("Enter first and second number number (3,4) : \n");
9    scanf("%d %d",&num1,&num2);
10    n1=num1;
11    n2=num2;
12
13    while(n2!=0){
14        rem=n1%n2;
15        n1=n2;
16        n2=rem;
17
18    }
19
20    gcd=n1;
21    lcm=(num1*num2)/gcd;
22
23    printf("GCD of %d and %d is %d\n",num1,num2,gcd);
24    printf("LCM of %d and %d is %d\n",num1,num2,lcm);
25
26
27    return 0;
28}
29
queries leading to this page
c program for gcd 2clcd gcd and lcd in c