google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to find the GCD and LCM of two numbers using functions - 2nd puc computer science

Write a program to find the GCD and LCM of two numbers using functions

// Write a program to find the GCD and LCM of two numbers using functions

#include<iostream.h>

#include<conio.h>

int a,b;

int gcd(int a,int b)

{

int r;

while(b!=0)

{

r=a%b;

a=b;

b=r;

}

return(a);

}

void main()

{

int gcd(int x,int y);

int product,lcm,g;

clrscr();

cout<<"Enter two numbers: ";

cin>>a>>b;

product=a*b;

g=gcd(a,b);

lcm=product/g;

cout<<"GCD="<<g<<endl;

cout<<"LCM="<<lcm<<endl;

getch();

}


Write a program to find the GCD and LCM of two numbers using functions Write a program to find the GCD and LCM of two numbers using functions Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.