google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to find gcd and lcm of two numbers - 2nd puc computer science

Write a c program to find gcd and lcm of two numbers

write a c program to find hcf (gcd) of two numbers,write a c program gcd of two numbers,write a c program to find gcd of two numbers,write a c program to find gcd in the given two numbers using while loop

Write a c program to find gcd and lcm of two numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int n1,n2,gcd,lcm,r,n,d;

clrscr();

printf("Enter two numbers: ");

scanf("%d%d",&n1,&n2);

if(n1>n2)

{

n=n1;

d=n2;

}

else

{

n=n2;

d=n1;

}

r=n1%n2;

while(r!=0)

{

n=d;

d=r;

r=n%d;

}

gcd=d;

lcm=n1*n2/gcd;

printf("GCD of %d and %d=%d\n",n1,n2,gcd);

printf("LCM of %d and %d=%d\n",n1,n2,lcm);

getch();

}

Output:

Enter two numbers: 4

2                                                                              

GCD of 4 and 2=2                                                               

LCM of 4 and 2=4       
Write a c program to find gcd and lcm of two numbers Write a c program to find gcd and lcm of two numbers Reviewed by Vision Academy on December 17, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.